Go to advanced search

by elParaguayo
Sun Nov 12, 2017 2:00 pm
Forum: Python
Topic: if command doesn't work
Replies: 1
Views: 280

Re: if command doesn't work

str(arr[2]) isn't doing what you think it is. Do a print statement and you'll see you get "b'C'" so your comparison fails. If you do need to convert the bytes to a string then you could do it like this: arr = line.decode("utf-8").split() and then if arr[2] == "C": or you could stick with what you've...
by elParaguayo
Thu Nov 09, 2017 10:18 am
Forum: Python
Topic: Shairport-sync metadata to websocket
Replies: 3
Views: 889

Re: Shairport-sync metadata to websocket

I've not done anything with tornado/websockets before but I like shairport-sync so I'm happy to help if I can. I wrote some code a while ago for retrieving metadata but, at the time, I had no interest in getting the artwork - I can dig out that code and have a look. As for the websockets stuff, can ...
by elParaguayo
Fri Nov 03, 2017 4:35 pm
Forum: Python
Topic: GUI(Tkinter) Is my program right?
Replies: 2
Views: 650

Re: GUI(Tkinter) Is my program right?

The best way to answer the "will it work" question for code is to run it and see. (Spoiler alert) the answer is "no", there are quite a few syntax errors that I can see (indentation is the main one). I'm assuming you're new to python (welcome to the forum!) as this seems to be different pieces of co...
by elParaguayo
Sat Oct 28, 2017 3:22 pm
Forum: Python
Topic: First time writing a decorator
Replies: 3
Views: 608

Re: First time writing a decorator

Here's an example (written in python 2 because that's what I learnt - I really should get used to python 3...): def my_decorator(func): print "my_decorator function called with one argument: {}".format(func) def wrapper(*args, **kwargs): print "Start of wrapper" print "Running wrapped function with ...
by elParaguayo
Sat Oct 28, 2017 4:18 am
Forum: Python
Topic: First time writing a decorator
Replies: 3
Views: 608

Re: First time writing a decorator

A bit more context would be helpful but it looks ok at the moment. Think about what's happening: when you use your decorator you are passing a function, not the function and its arguments ie @check_logged_in def my_func(arg): ... equates to my_func = check_logged_in(my_func) which, in turn, gives yo...
by elParaguayo
Fri Oct 27, 2017 9:11 pm
Forum: Python
Topic: Eval function in Python
Replies: 7
Views: 1010

Re: Eval function in Python

That's why I love this forum, I'm always learning things here. Never seen the compile function before.
by elParaguayo
Fri Oct 27, 2017 8:25 pm
Forum: Python
Topic: Eval function in Python
Replies: 7
Views: 1010

Re: Eval function in Python

Go with Dougie's example. He knows far more than me!
by elParaguayo
Fri Oct 27, 2017 8:23 pm
Forum: Python
Topic: Eval function in Python
Replies: 7
Views: 1010

Re: Eval function in Python

Actually, maybe it's just eval you're after. The input is just if you want to enter the string while your script is running.

See the docs: https://docs.python.org/2/library/functions.html#eval
by elParaguayo
Fri Oct 27, 2017 8:22 pm
Forum: Python
Topic: Eval function in Python
Replies: 7
Views: 1010

Re: Eval function in Python

"input()" in python 2 or "eval(input())" but make sure you're careful who has access otherwise you can have someone do some bad things to your pi!
by elParaguayo
Thu Oct 26, 2017 6:20 am
Forum: Python
Topic: Python import network error
Replies: 13
Views: 8666

Re: Python import network error

Yes, download the file and put it in the same folder as your script. It should work.
by elParaguayo
Tue Oct 24, 2017 7:32 am
Forum: Python
Topic: Python script not running via apache, but works in terminal
Replies: 3
Views: 1233

Re: Python script not running via apache, but works in terminal

This sounds like a permissions problem. When running from putty you are running with sudo but I assume Apache isn't running with root privileges (and it shouldn't be). Have a search on this forum for gpio via web pages it's been asked many times before. If you're still stuck then come back and ask f...
by elParaguayo
Fri Oct 20, 2017 3:22 pm
Forum: Python
Topic: problem sending data to php api with request library
Replies: 2
Views: 646

Re: problem sending data to php api with request library

You're not posting the same thing. According to your postman image, it looks like data should be:

Code: Select all

data = {"data": [ {"service_id":5,"datovivo":"dato","service_name":"nombre","enabled_service":"encendido","submenu":"sub","dispo":"disp"}]} 
Requests doesn't add anything to the payload.
by elParaguayo
Thu Oct 19, 2017 12:06 pm
Forum: Python
Topic: Looping an mp3
Replies: 10
Views: 1373

Re: Looping an mp3

using either os.system or subprocess has this effect. Good programmers will only use multi processes when the task requires it. Here your just wanting to do 1 thing at a time, play a MP3 then when it finishes play it again. Ha - I guess I'm a "bad" programmer then! I'd agree that pygame is worth lo...
by elParaguayo
Thu Oct 19, 2017 8:18 am
Forum: Python
Topic: Looping an mp3
Replies: 10
Views: 1373

Re: Looping an mp3

rpdom wrote:
Wed Oct 18, 2017 7:59 pm
Are you sure it doesn't play the track, then wait for 68 seconds before playing it again?
Having looked at the docs, it sounds like this would be the expected behaviour as the return value is the exit status which would only be available once the command has completed.
by elParaguayo
Thu Oct 19, 2017 7:00 am
Forum: Python
Topic: Looping an mp3
Replies: 10
Views: 1373

Re: Looping an mp3

Or have a go yourself! subprocess.call will run the command and wait until it finishes before running the next line.

The python docs generally recommend using subprocess instead of os.system anyway so it would be good to take a look.
by elParaguayo
Thu Oct 19, 2017 6:55 am
Forum: Python
Topic: Looping an mp3
Replies: 10
Views: 1373

Re: Looping an mp3

I think this is a good example of when using subprocess may be better. I can give you some code once I get into work!
by elParaguayo
Wed Oct 18, 2017 8:37 pm
Forum: Python
Topic: Looping an mp3
Replies: 10
Views: 1373

Re: Looping an mp3

Is this your actual code? There's a spelling mistake in os.system
by elParaguayo
Wed Oct 18, 2017 3:55 pm
Forum: Python
Topic: PyCups to print a text file with options
Replies: 1
Views: 2218

Re: PyCups to print a text file with options

I've never used pycups but am always keen to try to help! I've answered a few questions previously which may be some use to you: 1) Passing options to pycups: https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=180370&p=1147727#p1147727 2) Printing multiple copies: https://www.raspberrypi.org/fo...
by elParaguayo
Wed Oct 18, 2017 2:02 pm
Forum: Python
Topic: Sending by mail image files from a folder
Replies: 10
Views: 1167

Re: Sending by mail image files from a folder

There's no need to use ".close()" when using a "with" context manager structure. The close happens at the end of the block (or if there's an exception in the block).
by elParaguayo
Wed Oct 11, 2017 12:49 pm
Forum: Python
Topic: Joining code together
Replies: 8
Views: 1204

Re: Joining code together

The error regarding "out" should be easy enough to fix. The problem is that you only open and close the file if certain conditions are met. The best way to deal with this would be, instead of doing this: out = open('/home/pi/Documents/ZeroWGarden/Enviro/enviro_' + elogname + '.log', 'w') out.write('...
by elParaguayo
Mon Oct 09, 2017 2:23 pm
Forum: Python
Topic: Change PiCam file name to date and time
Replies: 32
Views: 4186

Re: Change PiCam file name to date and time

This line is wrong:

Code: Select all

camera = PiCamera
At the moment, camera is just a reference to the PiCamera class definition. You need to create an instance of the PiCamera as follows:

Code: Select all

camera = PiCamera()
by elParaguayo
Wed Oct 04, 2017 8:58 pm
Forum: Python
Topic: How To Import A Module Within A Module?
Replies: 7
Views: 865

Re: How To Import A Module Within A Module?

You'll probably need to share your code to get a decent answer on this but it sounds like you're missing an import time line somewhere.
by elParaguayo
Wed Oct 04, 2017 8:42 am
Forum: Python
Topic: Displaying sensor readings on a hd44780 LCD
Replies: 4
Views: 784

Re: Displaying sensor readings on a hd44780 LCD

Combining scripts doesn't mean putting one after the other. Your LCD code will never run because you've got an infinite loop ("while True:") in your top script. You should define all functions and initialise the LCD at the top of your script and then have one loop which retrieves the data and displa...
by elParaguayo
Wed Oct 04, 2017 8:40 am
Forum: Python
Topic: Displaying sensor readings on a hd44780 LCD
Replies: 4
Views: 784

Re: Displaying sensor readings on a hd44780 LCD

Please use code tags when posting code as you lose your indentation. It should look like this: #import import RPi.GPIO as GPIO import time sensor = 21 # define the GPIO pin our sensor is attached to GPIO.setmode(GPIO.BCM) # set GPIO numbering system to BCM GPIO.setup(sensor,GPIO.IN) # set sensor pin...
by elParaguayo
Tue Oct 03, 2017 5:51 pm
Forum: Python
Topic: Displaying sensor readings on a hd44780 LCD
Replies: 4
Views: 784

Re: Displaying sensor readings on a hd44780 LCD

Put that code to one side for the moment and start a separate script to get your LCD working. There are plenty of examples around of doing that.

Once you're familiar with using the LCD then you can combine your scripts.

Go to advanced search