Go to advanced search

by elParaguayo
Fri Aug 15, 2014 11:25 am
Forum: Python
Topic: Sending a UTF-8 email
Replies: 8
Views: 1880

Re: Sending a UTF-8 email

It's not necessarily anything to do with the email part of your code. It would help if you post the error message you get. However, I suspect it's a syntax error. You may need an encoding declaration at the top of your code. See http://stackoverflow.com/questions/6289474/working-with-utf-8-encoding-...
by elParaguayo
Thu Aug 14, 2014 7:37 am
Forum: Python
Topic: Python lists and dictionaries
Replies: 7
Views: 1925

Re: Python lists and dictionaries

Nice. Hadn't seen that before. Pretty neat answer. I think the only difference between that and the option in my post is that printing the AutoVivifcation object (using your values) would just print {'y': {'d': 'c'}, 'x': {'y': 'a', 'z': 'b'}} as it is essentially still a dict rather than a defaultd...
by elParaguayo
Wed Aug 13, 2014 10:00 pm
Forum: Graphics, sound and multimedia
Topic: mPanel - A Pi Media Panel
Replies: 7
Views: 5335

Re: mPanel - A Pi Media Panel

That looks pretty smart. Certainly way more professional looking than the Information Screen I put together (but then it was designed for much smaller screens).

Great work.
by elParaguayo
Wed Aug 13, 2014 9:58 pm
Forum: Python
Topic: noob would like a bit of advice; JSON
Replies: 23
Views: 4764

Re: noob would like a bit of advice; JSON

How does your phone come into this?

We're looking at controlling XBMC with GPIO buttons on the Pi. As XBMC is on the same machine as the GPIO buttons I would hope that you could just use "http://localhost:8080/jsonrpc" as your url.
by elParaguayo
Wed Aug 13, 2014 4:54 pm
Forum: Python
Topic: Python lists and dictionaries
Replies: 7
Views: 1925

Re: Python lists and dictionaries

Yes, you'd need to declare each level unless you use the class on my earlier post. If you only need to do it once then it's probably but with using the separate class.

But just do what you're happy with.
by elParaguayo
Wed Aug 13, 2014 3:22 pm
Forum: Python
Topic: Python lists and dictionaries
Replies: 7
Views: 1925

Re: Python lists and dictionaries

Another way of doing this is by subclassing the dict as follows (I take no credit for writing this code by the way - see this post on stackoverflow): class AutoVivification(dict): """Implementation of perl's autovivification feature.""" def __getitem__(self, item): try: return dict.__getitem__(self,...
by elParaguayo
Tue Aug 12, 2014 7:31 pm
Forum: Python
Topic: noob would like a bit of advice; JSON
Replies: 23
Views: 4764

Re: noob would like a bit of advice; JSON

You're trying to do two things which are incompatible. You can't use the GPIO script within XBMC because it needs root privileges. That, in turn, means you can't use the xbmc module. However, you can use the eventclient script that I provided a link to in my earlier post or JSON. JSON is really the ...
by elParaguayo
Mon Aug 11, 2014 8:21 pm
Forum: Python
Topic: Struggling to follow game development lecture
Replies: 1
Views: 545

Re: Struggling to follow game development lecture

Your Main class has a method called "reset_currentgame" but the error says your script is trying to call "reset_current_game". You just need to make sure you're being consistent. Don't worry, this will happen lots of times when you start out. The more errors you see, the easier you'll find it to deb...
by elParaguayo
Mon Aug 11, 2014 8:13 pm
Forum: Python
Topic: noob would like a bit of advice; JSON
Replies: 23
Views: 4764

Re: noob would like a bit of advice; JSON

Nice!

Sometimes when I'm writing code I think that clean prompt after I import my code is the most beautiful sight. I need to get out more...

If you've got a button hooked up to your pins just try some really raw code in the python shell to see if it's working.
by elParaguayo
Fri Aug 08, 2014 11:53 am
Forum: Python
Topic: Raspberry Pi Alarm!
Replies: 8
Views: 2399

Re: Raspberry Pi Alarm!

I had a quick look at the code on that page. Are you sure it's displayed correctly? It looks like there's an indentation error following a "while True:" statement where the following line is not indented appropriately. The Try... Except... blocks look odd too. it seems to go Try... Try... Except... ...
by elParaguayo
Fri Aug 08, 2014 8:26 am
Forum: Python
Topic: Using 2 states for button presses
Replies: 22
Views: 2576

Re: Using 2 states for button presses

Is that code an actual copy and paste? Looks like there are indentation errors in the "while True" block and your kill command looks wrong - I assume you mean "sudo killall mpg321". Also, you don't need the semicolon after your sleep command. The script will, when indented properly, apparently run t...
by elParaguayo
Thu Aug 07, 2014 5:00 pm
Forum: Python
Topic: Keeping the variable´s value
Replies: 9
Views: 1746

Re: Keeping the variable´s value

rafalybelen,

Can you copy your exact code into your post. It looks like there's a comment after the "open" command. My guess is that you've got a Spanish word there "podrá" and that's causing the error.
by elParaguayo
Wed Aug 06, 2014 8:00 am
Forum: Python
Topic: Launching script via button press - newbie attempt
Replies: 18
Views: 2482

Re: Launching script via button press - newbie attempt

Yes. The "while True:" line is the start of the loop. Everything in that block will keep on repeating. As a result, your second while loop doesn't get called. Quick example: from time import sleep while True: print "This is loop 1" sleep(1) while True: print "This is loop 2" sleep(1) #If you run thi...
by elParaguayo
Wed Aug 06, 2014 6:36 am
Forum: Python
Topic: Launching script via button press - newbie attempt
Replies: 18
Views: 2482

Re: Launching script via button press - newbie attempt

The code for the second button needs to be in the same while loop otherwise it won't get called.
by elParaguayo
Tue Aug 05, 2014 9:13 pm
Forum: Python
Topic: noob would like a bit of advice; JSON
Replies: 23
Views: 4764

Re: noob would like a bit of advice; JSON

OK - it sounds like that script is probably exactly what you need... In answer to your questions: 1) You can put the script wherever you like. You'll need to call it from outside of XBMC in order to give it root privileges, so, for that reason, you might want to keep it outside of the XBMC folder. 2...
by elParaguayo
Tue Aug 05, 2014 8:06 am
Forum: Python
Topic: Calling LED's as separate outputs
Replies: 17
Views: 2525

Re: Calling LED's as separate outputs

Firstly, apologies for unwittingly changing the topic of this thread!

Back to the original topic... Visser, if you're still having problems can you paste your latest code and we'll take a look. Thanks.
by elParaguayo
Mon Aug 04, 2014 6:18 pm
Forum: Python
Topic: noob would like a bit of advice; JSON
Replies: 23
Views: 4764

Re: noob would like a bit of advice; JSON

OK. Step back. Why don't you explain exactly what you're trying to do. autoexec.py was an old way for scripts to run when starting XBMC. This has now been replaced by services. However, given that you're looking to use GPIO, you're probably best doing this in a script outside of XBMC as the script n...
by elParaguayo
Mon Aug 04, 2014 10:33 am
Forum: Python
Topic: Calling LED's as separate outputs
Replies: 17
Views: 2525

Re: Calling LED's as separate outputs

Try using an array. led_pin = [23, 24, 25, 17, 27] Reference each element with for i in range(0,5): GPIO.output(led_pin[i],True) sleep(1) GPIO.output(led_pin[i],False) I hate to change some of Dougie's code as I'm sure he knows far more than I do about programming, however this bit of code is, to m...
by elParaguayo
Sat Aug 02, 2014 6:15 pm
Forum: Python
Topic: noob would like a bit of advice; JSON
Replies: 23
Views: 4764

Re: noob would like a bit of advice; JSON

OK. So this script is meant to control XBMC (or, as it's now apparently called, Kodi...) Therefore the url needs to point to the web address of your XBMC server (assuming you've enabled access via HTTP in XBMC). There is a line in the script url = 'http://192.168.1.138:8888/jsonrpc' So you need to c...
by elParaguayo
Sat Aug 02, 2014 6:17 am
Forum: Python
Topic: Problems with controlling mplayer by GPIO using Python
Replies: 3
Views: 2473

Re: Problems with controlling mplayer by GPIO using Python

That's probably your problem then. You can't send a key to a program that's no longer running.
by elParaguayo
Fri Aug 01, 2014 7:21 pm
Forum: Python
Topic: Problems with controlling mplayer by GPIO using Python
Replies: 3
Views: 2473

Re: Problems with controlling mplayer by GPIO using Python

Are you sure mplayer is still running? If I recall correctly, I've seen broken pipe messages when the process has actually closed.
by elParaguayo
Wed Jul 30, 2014 11:37 am
Forum: Python
Topic: How do you write the % symbol to a pygame screen?
Replies: 5
Views: 1318

Re: How do you write the % symbol to a pygame screen?

That's strange. I've never had a problem with pygame printing the "%" sign. This post shows the chance of rain printed with the % sign. The code for those lines was: weatherpop = "Rain: " + hourly["pop"] + "%" poplabel = self.myfont.render(weatherpop, 1, (255, 255, 255)) hourrect.blit(poplabel, (10,...
by elParaguayo
Mon Jul 28, 2014 8:46 am
Forum: Graphics, sound and multimedia
Topic: One-side headphone output
Replies: 12
Views: 3345

Re: One-side headphone output

Your code as it is would, I think, cause both files to play at the same time. If you're only going to play one sound at a time, I'd probably set the number of channels to 1. Also, if you just want to play each sound, instead of doing this: while index<=len(sounds_list): sounda=pygame.mixer.Sound(sou...
by elParaguayo
Sun Jul 27, 2014 6:20 pm
Forum: Graphics, sound and multimedia
Topic: One-side headphone output
Replies: 12
Views: 3345

Re: One-side headphone output

Do you want both of those sounds to play at the same time? When you say plays on all 8 channels at once, what do you mean? My understanding was that the pygame mixer would just load a new sound into the next available channel. In your code you create some sound objects, but you're not capturing the ...
by elParaguayo
Sun Jul 27, 2014 5:51 pm
Forum: Graphics, sound and multimedia
Topic: One-side headphone output
Replies: 12
Views: 3345

Re: One-side headphone output

You can do it like this: import pygame from time import sleep # intialise mixer pygame.mixer.init() # Load the sound file snd = pygame.mixer.Sound("/path/to/sound/file") # Play the file and put it into a channel object channel = snd.play() # Mute left speaker channel.set_volume(1,0) sleep(2) # Mute ...

Go to advanced search