Go to advanced search

by elParaguayo
Thu Aug 31, 2017 5:54 am
Forum: Python
Topic: not all arguments converted during string formatting
Replies: 4
Views: 3757

Re: not all arguments converted during string formatting

That's not a string formatting command, it looks like you just wanted to append the value of uva to the end of the string.

Try this:

Code: Select all

print ("Raw UVA is : {}".format(uva))
Or

Code: Select all

print ("Raw UVA is : %s" % uva)
by elParaguayo
Wed Aug 30, 2017 7:04 am
Forum: Python
Topic: Video file name + date time now
Replies: 2
Views: 1281

Re: Video file name + date time now

try this: from datetime import datetime from picamera import PiCamera camera = PiCamera() camera.rotation = 180 camera.start_preview() timestamp = datetime.now().strftime("%y%m%d_%H%M%S") camera.start_recording("/home/pi/{}.h264".format(timestamp)) This will create a file called something like 17083...
by elParaguayo
Fri Aug 25, 2017 7:52 am
Forum: Python
Topic: Write output in same line using python
Replies: 5
Views: 1161

Re: Write output in same line using python

I don't think your example writes to a file as per the OP's question.

Would help if the OP posted their code so we can provide specific help.
by elParaguayo
Tue Aug 22, 2017 8:57 am
Forum: Other projects
Topic: LED Cube RGB 12x12x12
Replies: 7
Views: 4290

Re: LED Cube RGB 12x12x12

I found this by chance and I'm pleased I did. Amazing project.
by elParaguayo
Tue Aug 22, 2017 12:37 am
Forum: Python
Topic: Runnning python script on boot
Replies: 3
Views: 1629

Re: Runnning python script on boot

Have you tried using the to path to sendmail.py?
by elParaguayo
Fri Aug 18, 2017 5:21 am
Forum: Python
Topic: Problem getting PyGame installed
Replies: 2
Views: 556

Re: Problem getting PyGame installed

Well, I think the error is because of the backslashes​ in your command.

However, I thought pygame was preinstalled on raspbian. Have you checked?
by elParaguayo
Thu Aug 17, 2017 1:40 pm
Forum: Python
Topic: Screen capture - calling scrot from Python 3 not working
Replies: 5
Views: 1746

Re: Screen capture - calling scrot from Python 3 not working

Great. So, using the example above, you should be able to save files in whichever folder you want.
by elParaguayo
Wed Aug 16, 2017 8:43 pm
Forum: Python
Topic: Screen capture - calling scrot from Python 3 not working
Replies: 5
Views: 1746

Re: Screen capture - calling scrot from Python 3 not working

Does scrot allow you to specify a filename for the image? If so, you could pass that too and save the file exactly where you want. e.g.

Code: Select all

import subprocess

image_file = "/home/pi/screenshot.png"

subprocess.call(["scrot", image_file])
by elParaguayo
Wed Aug 16, 2017 3:50 pm
Forum: Python
Topic: Screen capture - calling scrot from Python 3 not working
Replies: 5
Views: 1746

Re: Screen capture - calling scrot from Python 3 not working

When you say "it fails", can you tell us what happens and what you expect to happen.
by elParaguayo
Wed Aug 16, 2017 3:13 pm
Forum: Python
Topic: App used to start at boot, now doesn't
Replies: 3
Views: 623

Re: App used to start at boot, now doesn't

Does xdotool give a different return code when it fails? If it returns 0 when successfully executed but anything else if there's an error then you could use subprocess.check_call to call the command and do this inside a try... except... block. If there's an error, you can sleep for a bit and then tr...
by elParaguayo
Wed Aug 16, 2017 11:16 am
Forum: Python
Topic: How to combine these 3 lists into a single list of dictionary?
Replies: 7
Views: 950

Re: How to combine these 3 lists into a single list of dictionary?

Actually, it's not a dictionary comprehension. It's a list comprehension where the members of the list are dictionaries. A dictionary comprehension is different (not that it really matters here!)
by elParaguayo
Wed Aug 16, 2017 11:07 am
Forum: Python
Topic: How to combine these 3 lists into a single list of dictionary?
Replies: 7
Views: 950

Re: How to combine these 3 lists into a single list of dictionary?

No. Mine was virtually identical (just different variable names)!
by elParaguayo
Wed Aug 16, 2017 10:56 am
Forum: Python
Topic: How to combine these 3 lists into a single list of dictionary?
Replies: 7
Views: 950

Re: How to combine these 3 lists into a single list of dictionary?

EDIT: Gah - by the time I'd managed to type a nice dictionary comprehension you'd found the answer!
by elParaguayo
Wed Aug 16, 2017 7:34 am
Forum: Python
Topic: Writing to a file
Replies: 1
Views: 405

Re: Writing to a file

Code: Select all

w.write("{} {} {} {} {} {}\n".format(dateTime, startTemp, tempP1, tempP2, tempP3, tempP4))
There are a few links in this post which can explain the string formatting syntax.
by elParaguayo
Tue Aug 15, 2017 2:27 pm
Forum: Python
Topic: help me , my python script doesn't work
Replies: 5
Views: 1027

Re: help me , my python script doesn't work

Well, there's no need for the OP to use the construct unless they were planning to import any of their functions into a separate script. i.e. this could have been import time import mcpforsmoke as mcpl import mcpforlpg as mcp2 smokeLevel= 0 lpgLevel=0 def readSmokeLevel(): global smokeLevel smokeLev...
by elParaguayo
Tue Aug 15, 2017 5:39 am
Forum: Python
Topic: help me , my python script doesn't work
Replies: 5
Views: 1027

Re: help me , my python script doesn't work

I think you're missing some underscores. It's

Code: Select all

if __name__ == "__main__":
by elParaguayo
Mon Aug 14, 2017 8:50 pm
Forum: Python
Topic: urllib stopped working
Replies: 6
Views: 1760

Re: urllib stopped working

You have got a file called email.py. That's clashing with the email package in the standard library.

You need to rename your file and delete the email.pyc file.
by elParaguayo
Fri Aug 11, 2017 3:58 pm
Forum: Python
Topic: Control-C in Python
Replies: 9
Views: 3153

Re: Control-C in Python

Don't thank me yet. They may not work!
by elParaguayo
Fri Aug 11, 2017 3:24 pm
Forum: Python
Topic: Control-C in Python
Replies: 9
Views: 3153

Re: Control-C in Python

Then you might want to try using the subprocess module and use Popen to start the process. You can then send signals to the process. However, I have read that this doesn't always work so you may want to try and report back: Option 1: import subprocess cmd = ['arecord', '-c2', '-f', 'S32_LE', '-r', '...
by elParaguayo
Fri Aug 11, 2017 5:16 am
Forum: Python
Topic: Using Python Variables in HTML in multiline Python string
Replies: 8
Views: 19354

Re: Using Python Variables in HTML in multiline Python string

Yes. You can do this:

Code: Select all

a = "webpage.com/image.jpg"

message = """<html>
<head></head>
<body><img src="{URL}"></body>
</html>"""

new_message = message.format(URL=a)
# I've put the formatted message in a new variable 
# so you can reuse "message" as a template
by elParaguayo
Fri Aug 11, 2017 5:13 am
Forum: Python
Topic: PEP
Replies: 6
Views: 1199

Re: PEP

In my opinion, the answer is 'no'. Some of them may be interesting but I'm not sure how beneficial it would be to your own coding.

The exception is PEP8. Read that one. It will help your coding style and help people who read your code.
by elParaguayo
Thu Aug 10, 2017 11:03 am
Forum: Python
Topic: Noob lost been reading this code for hours
Replies: 7
Views: 1192

Re: Noob lost been reading this code for hours

Fair enough.
by elParaguayo
Thu Aug 10, 2017 9:35 am
Forum: Python
Topic: Noob lost been reading this code for hours
Replies: 7
Views: 1192

Re: Noob lost been reading this code for hours

I'm not sure the "list" line is necessary. Have a look at this: my_dict = {"key1": "value1", "key2": "value2"} list_of_keys = list(my_dict.keys()) for key in list_of_keys: print(my_dict[key]) outputs value2 value1 Simpler version: for key in my_dict: print(my_dict[key]) outputs value2 value1
by elParaguayo
Wed Aug 09, 2017 8:41 am
Forum: Python
Topic: Using subprocess.call to use arecord stopped working overnight
Replies: 3
Views: 570

Re: Using subprocess.call to use arecord stopped working overnight

I've no idea if this is the problem if the code worked before, but I don't think you can use 'call' like that. The line should be:

Code: Select all

call(['arecord','-d', '10', '-D', 'plughw:0,0', '-f', 'cd', 'testing123.wav'])
Each argument needs to be a separate item in the list.
by elParaguayo
Tue Aug 08, 2017 11:19 am
Forum: Python
Topic: Installing aubio for Python3
Replies: 4
Views: 1317

Re: Installing aubio for Python3

Mike,

There isn't a file called aubio.py or aubio.pyc in your folder is there? That error message can be caused by python importing the wrong file.

Go to advanced search