Go to advanced search

by billio
Mon Nov 18, 2019 7:22 pm
Forum: Python
Topic: array's confusion
Replies: 9
Views: 773

Re: array's confusion

I am not sure exactly what you want but your array contains python "bytes" which are kind of a "type of string", that's why when you print them some appear as hex numbers and some appear as letters. Using Python3 these are two ways you can convert the bytes to hexadecimal numbers as strings or as in...
by billio
Wed Nov 13, 2019 9:08 pm
Forum: Python
Topic: Which type of protocol being used between PI and PC in program
Replies: 10
Views: 740

Re: Which type of protocol being used between PI and PC in program

pymssql uses the Tabular Data Stream (TDS), which is an application layer protocol (i.e sits on top of the other protocols discussed above). It is used to transfer data between a database server and a client. It was initially designed and developed by Sybase Inc. for their Sybase SQL Server relation...
by billio
Sun Nov 10, 2019 9:21 am
Forum: Python
Topic: Conversion
Replies: 17
Views: 1003

Re: Conversion

There may be a better way than this but :

Code: Select all

>>> a = 0x81233333
>>> b = a.to_bytes(4,"big",signed=False)
>>> c = [int(i) for i in b]
>>> c
[129, 35, 51, 51]
by billio
Sun Nov 10, 2019 12:13 am
Forum: Python
Topic: Conversion
Replies: 17
Views: 1003

Re: Conversion

Python 2 has normal length integers and long integers, the latter being represented with a trailing L. >>> type(666L) <type 'long'> >>> type(666) <type 'int'> I believe that is where the L comes from. But can I ask what the purpose of the function "def convert_long_to_bytes" is. If it is to convert ...
by billio
Sat Nov 09, 2019 10:33 am
Forum: Python
Topic: Conversion
Replies: 17
Views: 1003

Re: Conversion

I think you need

Code: Select all

struct.pack(">f", x).hex()
as described here https://docs.python.org/3/library/stdtypes.html
The type 'bytes' does not have an encode() function in python3.
by billio
Fri Nov 08, 2019 4:20 pm
Forum: Python
Topic: SOLVED - Frustrating problem with python code in Flask application
Replies: 4
Views: 585

Re: SOLVED - Frustrating problem with python code in Flask application

Yes I have tripped up over that a few times. You can also avoid the problem with :

Code: Select all

return bytearray(self._pattern)
# creates a new bytearray
by billio
Thu Nov 07, 2019 10:57 pm
Forum: Python
Topic: SOLVED - Frustrating problem with python code in Flask application
Replies: 4
Views: 585

Re: SOLVED - Frustrating problem with python code in Flask application

Although I haven't seen your code and my apologies if I am wrong, but I expect you were doing something like this : class A() : b = {1:0,2:0} def __init__(self) : self.b = A.b def up(self,c,d) : self.b[1] = c self.b[2] = d print(f"{A.b},{self.b}") The output being : >>> x = A() >>> x.b {1: 0, 2: 0} ...
by billio
Fri Nov 01, 2019 8:37 pm
Forum: Python
Topic: Measuring time of operation...
Replies: 12
Views: 995

Re: Measuring time of operation...

Have you considered this in Python3 :

Code: Select all

import time
import math

start = time.perf_counter()
# wait a bit or something happens
end = time.perf_counter()

duration = end - start

fractions_of_a_second, seconds = math.modf(duration)
then convert seconds to hours and minutes as you wish.
by billio
Tue Oct 29, 2019 9:39 pm
Forum: Python
Topic: How do I get the slide show to stop
Replies: 7
Views: 1308

Re: How do I get the slide show to stop

The reason this slideshow keeps returning to the begining over and over again is because it uses the cycle function from the itertools module. The purpose of this function is to create an iterator that cycles through a list over and over again. from itertools import cycle ... self.set_images(self,im...
by billio
Fri Oct 25, 2019 2:48 pm
Forum: Python
Topic: [solved] Puzzled by two simple hex-dec-string mixup
Replies: 7
Views: 1966

Re: Puzzled by two simple hex-dec-string mixup

\xC0 is a representation of a character not a number, it is upper-case A grave. See the Latin-1 character set. This is what the error message is saying. I am not sure why you think \xC0 should be a number. 0xC0 is the manner in which python represents hex numbers in a program, just the same as 1, 3....
by billio
Sat Mar 16, 2019 11:10 am
Forum: Raspberry Pi OS
Topic: Stretch dist-upgrade - failed to Load Kernel Modules
Replies: 0
Views: 439

Stretch dist-upgrade - failed to Load Kernel Modules

I just performed a dist-upgrade and on rebooting the system the boot showed the message : FAILED .. failed to Load Kernel Modules the boot carried on the desktop as expected but the USB mouse and keyboard no longer work so I am stuck. Switching off and on produces the same result. Is there any solut...
by billio
Sat Jul 14, 2018 12:03 pm
Forum: Python
Topic: Live keyboard entry onto display
Replies: 3
Views: 565

Re: Live keyboard entry onto display

pygame has functions to handle keyboard entry, it is already loaded on the RPi

There is also a python module called 'keyboard' that can loaded using pip.
by billio
Tue Aug 29, 2017 12:16 pm
Forum: General discussion
Topic: Camera
Replies: 4
Views: 906

Re: Camera

I have used an application called "Cheese" to connect a USB camera to a RPi. Although I have not used it, the OpenCV package looks as though it might be a good starting point for programming. If you want a Python 2 interface to OpenCV : sudo pip install opencv with documentation at http://opencv-pyt...
by billio
Sat Mar 25, 2017 12:12 pm
Forum: Raspberry Pi OS
Topic: Black title bar background for in-focus window
Replies: 1
Views: 722

Re: Black title bar background for in-focus window

I have avoided this problem by loading obconf (openbox configuration) and switching from the Pixel theme to one of the other themes. The text and the icons are now displayed when the window is in focus.
Will it be possible to edit the Pixel theme ?. Where is this stored ?.
by billio
Tue Mar 21, 2017 8:54 pm
Forum: Raspberry Pi OS
Topic: Black title bar background for in-focus window
Replies: 1
Views: 722

Black title bar background for in-focus window

I have been having this problem for a few weeks. I have an up-to-date version of Pixel. The title bar of the in-focus window has a black background and therefore it is impossible to see the text and window icons so for example I cannot click on an icon to close the window. When the window is not in ...
by billio
Sat Mar 28, 2015 3:53 pm
Forum: Troubleshooting
Topic: urlopen
Replies: 3
Views: 1164

Re: urlopen

Just a simple update on this thread. There is a Python library called "feedparser" which can be used to directly parse an RSS/Atom response. It presents the XML response as a dictionary. This library is installed using pip. So to get the most recent weather observation for a place : import feedparse...
by billio
Tue Oct 28, 2014 12:12 am
Forum: Python
Topic: Exiting from a for and while loop
Replies: 5
Views: 2473

Re: Exiting from a for and while loop

Your code is a little obtuse, is this what you meant to happen ?. Set 10 high, then Set 26 high and low very quickly for 1000 times or until the switch status is 0, then Set 10 low def function1(): totalSteps = 1000 stepsDone = 0 GPIO.output(10,GPIO.HIGH) while switch == 1 and stepsDone < totalSteps...
by billio
Sat Oct 25, 2014 6:56 pm
Forum: Python
Topic: How to use "or"
Replies: 6
Views: 1478

Re: How to use "or"

Just to indicate an alternative way of doing this avoiding the "or" :

Code: Select all

if answer in ["continue","i want to continue"] :
    # do whatever you want to do
or in a different situation :

Code: Select all

if answer not in ["quit","stop","halt","bye"] :
    # carry on
by billio
Wed Oct 15, 2014 12:22 am
Forum: Python
Topic: Right way of PRINTING values in python3?
Replies: 5
Views: 1211

Re: Right way of PRINTING values in python3?

Try this, do you still have the error : print( """ TX23 sensor reading Datetime: {dt:s} Speed: {sp:s} m/s Direction: {di:s} Degrees: {de:s}""" .format( dt=datetime.datetime.fromtimestamp(output['timestamp']).strftime('%d/%m/%Y - %H:%M:%S')), sp=data['speed'], di=data['direction'], de=data['degrees']...
by billio
Tue Oct 14, 2014 11:35 pm
Forum: Python
Topic: PiFace Inputs
Replies: 10
Views: 2087

Re: PiFace Inputs

This discussion on "stackoverflow" will help. http://stackoverflow.com/questions/419163/what-does-if-name-main-do If you have any questions about Python, stackoverflow is a good place to look for an answer. However, it is possibly better to use this forum for specific Raspberry Pi related Python que...
by billio
Fri Oct 03, 2014 8:43 pm
Forum: Python
Topic: Cherrypy.config.update problem
Replies: 3
Views: 1848

Re: Cherrypy.config.update problem

Just looking at your code, the return line in def index(self): is incorrectly indented. Also, in the html, the meta tag should be within <head></head> tags. And in your meta tag, the content attribute is not properly quoted: "6" In the examples I have seen, cherrypy.config.update() is used before ch...
by billio
Mon Sep 22, 2014 10:13 pm
Forum: Python
Topic: Send Data from RPi to RPi via WiFi
Replies: 9
Views: 4203

Re: Send Data from RPi to RPi via WiFi

You might make some progress by reading this :

https://docs.python.org/3/howto/sockets.html

which is a basic introduction to network programming in Python.
by billio
Mon Sep 22, 2014 8:05 am
Forum: Camera board
Topic: Picamera import problem
Replies: 1
Views: 672

Re: Picamera import problem

An update to the firmware between 15th and 19th September looks to have fixed this problem. "import picamera" now works OK. Thanks.
by billio
Thu Sep 18, 2014 10:55 pm
Forum: Camera board
Topic: Picamera import problem
Replies: 1
Views: 672

Picamera import problem

When I try to import picamera I get an error : OSError: libmmal_components.so: cannot open shared object: No such file or directory Please can someone give me a hint on how to solve this problem. Just before trying out picamera and finding this error message I have updated operating system and kerne...
by billio
Wed Sep 10, 2014 6:39 pm
Forum: Python
Topic: Python with dallas temp and photocell sensors
Replies: 2
Views: 967

Re: Python with dallas temp and photocell sensors

Is it not something to do with
lines =read_temp_raw
this is assigning the function read_temp_raw to lines, not a list of text lines returned by read_temp_raw.
The error message is telling you that lines contains a function, not a list .

Go to advanced search