Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
king_kilr
May 25, 2007

m0nk3yz posted:

Interesting? It's pure awesome and win. I spoked to a few people about it today, and it's very very real. I could see this supplanting CPython-trunk quickly should they hit the goals for this year.

So jealous of people already at PyCon, one more day of class then I come home and join you guys no Friday. Looking forward to your talks, perhaps I'll see you there.

Adbot
ADBOT LOVES YOU

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!
I cry for my lack of PyCon, again. gently caress the accounting department, have fun guys.

Scaevolus
Apr 16, 2007

king_kilr posted:

For those who are interested in VM work or just want their Python faster this seems to be an intersting project: http://code.google.com/p/unladen-swallow/

It would be awesome if they met all these goals (JIT & no GIL?!), but the pessimist in me says they'll lose steam before they reach any real results.

I hope they prove me wrong.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Scaevolus posted:

It would be awesome if they met all these goals (JIT & no GIL?!), but the pessimist in me says they'll lose steam before they reach any real results.

I hope they prove me wrong.

According to their site, they've got a release out and it's already 20% faster than cpython.

Zombywuf
Mar 29, 2008

Janin posted:

According to their site, they've got a release out and it's already 20% faster than cpython.

Where did you find that number? Their benchmark page appears devoid of benchmarks.

ATLbeer
Sep 26, 2004
Über nerd

Zombywuf posted:

Where did you find that number? Their benchmark page appears devoid of benchmarks.

http://code.google.com/p/unladen-swallow/wiki/Releases

code:
2to3:
Min: 22.888 -> 20.299: 12.75% faster
Avg: 22.926 -> 20.329: 12.77% faster
Significant (t=145.835478, a=0.95)

Django:
Min: 0.596 -> 0.554: 7.52% faster
Avg: 0.598 -> 0.557: 7.43% faster
Significant (t=297.475166, a=0.95)

Pickle (complex):
Min: 1.023 -> 0.409: 150.36% faster
Avg: 1.053 -> 0.410: 157.17% faster
Significant (t=1102.029662, a=0.95)

Pickle (simple):
Min: 1.223 -> 0.868: 40.83% faster
Avg: 1.229 -> 0.876: 40.20% faster
Significant (t=695.483070, a=0.95)

PyBench:
Min: 46961 -> 38795: 21.05% faster
Avg: 47775 -> 39635: 20.54% faster

SlowPickle:
Min: 1.236 -> 1.072: 15.22% faster
Avg: 1.239 -> 1.076: 15.17% faster
Significant (t=497.615245, a=0.95)

SlowSpitfire:
Min: 0.762 -> 0.670: 13.87% faster
Avg: 0.764 -> 0.671: 13.80% faster
Significant (t=452.978688, a=0.95)

SlowUnpickle:
Min: 0.606 -> 0.528: 14.63% faster
Avg: 0.607 -> 0.530: 14.60% faster
Significant (t=581.549445, a=0.95)

Unpickle (complex):
Min: 0.738 -> 0.536: 37.71% faster
Avg: 0.746 -> 0.547: 36.24% faster
Significant (t=122.112665, a=0.95)

Unpickle (simple):
Min: 0.756 -> 0.486: 55.60% faster
Avg: 0.774 -> 0.493: 56.91% faster
Significant (t=331.578243, a=0.95)

king_kilr
May 25, 2007

Scaevolus posted:

It would be awesome if they met all these goals (JIT & no GIL?!), but the pessimist in me says they'll lose steam before they reach any real results.

I hope they prove me wrong.

I too am a forever skeptic, however it appears that all of the group members are Google employees, and one of their members in a Cpython core contributer, so there's hope!

Phrog
Aug 24, 2005

That damn green thing
Okay, I think I am retarded.

I'm trying to pick up programming as a hobby and at the recommendation of Ask/Tell I am learning Python. I downloaded it last night, played around in IDLE for a half-hour, copy/pasted some stuff into it from the web to see what would happen, etc and it was cool.

Fast forward to this morning and now I have brickwalled really really hard because of a problem that I can hardly even comprehend the existence of.

IDLE will not run anything past the first line.

I didn't have this problem yesterday, so I have zero clue what is causing this. For instance:
code:
name = raw_input('What is your name?\n') # \n is a newline
print 'Hi', name
This should prompt python to ask me to put in a name and then print "Hi (name)". However, after copy/pasting and hitting enter I get this instead:



So... what am I doing wrong?

No Safe Word
Feb 26, 2005

Phrog posted:

So... what am I doing wrong?

It's evaluating the first line, which specifically waits for user input. So it then waits until it sees the next newline (normally the user would type in their name and hit enter) and once it does it stores that into name.

So I bet if you just typed name you'd see "print 'Hi', name"

wrok
Mar 24, 2006

by angerbotSD

Phrog posted:

So... what am I doing wrong?

Copying and pasting (what No Safe Word said ^^^)

code:
IDLE 2.6.1      
>>> name = raw_input('What is your name?\n') # \n is a newline
print 'Hi', name

What is your name?
wrok
>>> name = raw_input('What is your name?\n') # \n is a newline
What is your name?
wrok
>>> print 'Hi', name
Hi wrok
>>> 
IDLE is reading your two lines all at once and not executing all of it. Each line should be a single (you guessed it!) line. The exception to this is while defining a function or class or whatnot.

code:
>>> def checkthisyo():
	name = raw_input('What is your name?\n') # \n is a newline
	print 'Hi', name

	
>>> checkthisyo()
What is your name?
wrok
Hi wrok
>>> 

Kire
Aug 25, 2006
Another Tkinter question: I want to display 4 buttons in a small window, each equal size, two packed against the top and filling the horizontal space, and two packed against the bottom. But, I'm not sure how to combine w.pack(side=LEFT) and w.pack(side=BOTTOM) into BOTTOM LEFT.

The only way to stack buttons vertically is to use w.pack() with no args, but I need args to have some of them be horizontally stacked.

Modern Pragmatist
Aug 20, 2008

Kire posted:

Another Tkinter question: I want to display 4 buttons in a small window, each equal size, two packed against the top and filling the horizontal space, and two packed against the bottom. But, I'm not sure how to combine w.pack(side=LEFT) and w.pack(side=BOTTOM) into BOTTOM LEFT.

The only way to stack buttons vertically is to use w.pack() with no args, but I need args to have some of them be horizontally stacked.

Pack is not a very flexible way to manage your layout. Look into using grids

BeefofAges
Jun 5, 2004

Cry 'Havoc!', and let slip the cows of war.

I've got a question for you Python experts about a program I'm writing:

I'm using matplotlib, SciPy, and PyWin32. Is it possible to make a single package out of my program plus these modules that will set itself up? My program is just a single .py, plus an .exe and some text files. If this is possible in Windows, is it also possible in OS X (without PyWin32, of course)? If it was possible to also include Python itself in this package that would be really nice, but it's not quite as important.

I could just include a readme saying install this, then this, then this, and so on, but it would be a lot more convenient if it was just one installer (especially if I could make it a silent installer). This is the first real app I've ever written, so I'm a little lost.

WickedMetalHead
Mar 9, 2007
/dev/null
py2exe and py2app Will pack up a python program into a .exe and a .app. I've never personally used them but i do believe those are the standard for packing like that.

If you don't want to do that, you should be able to use something like easy_install to package your product up, and then have it list dependencies. This will then download the things they don't already have, and use the things they already have installed on their system.

Although im not sure if easy_install works in windows or Mac, i've only used it in Linux.

darknife
Feb 23, 2009
How do I reference and use a object( an integer) in a function that is defined outside of it?

For example:
code:
guesses = 0

def guesses(x):
   if x == True:
      guesses += 1
   else:
      guesses -= 1
That would return an error saying "Referencing a object(guesses) not yet defined."

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

darknife posted:

How do I reference and use a object( an integer) in a function that is defined outside of it?

code:
guesses = 0

def guesses(x):
   global guesses # Add this line.
   if x == True:
      guesses += 1
   else:
      guesses -= 1
Might want to have different names for your variable and function, but it's up to you. :)

Haha owned son! Though you added the cautionary tale.
vvvv

pokeyman fucked around with this message at 07:46 on Mar 28, 2009

hlfrk414
Dec 31, 2008
Because by using the variable, you're declaring guesses in the local scope. You need to say guesses is global.
code:
guesses = 0

def guesses(x):
   global guesses
   if x == True:
      guesses += 1
   else:
      guesses -= 1
You should avoid this for the most part. For simple scripts it makes sense but as your code becomes more complicated the global variable guesses will be harder to control and track as it is used more.

EDIT : Too slow!

darknife
Feb 23, 2009

hlfrk414 posted:

Because by using the variable, you're declaring guesses in the local scope. You need to say guesses is global.
code:
guesses = 0

def guesses(x):
   global guesses
   if x == True:
      guesses += 1
   else:
      guesses -= 1
You should avoid this for the most part. For simple scripts it makes sense but as your code becomes more complicated the global variable guesses will be harder to control and track as it is used more.

EDIT : Too slow!


Well, I know that using the same name is not good practice. I don't do that. It was just an example where I messed up on the names.

And hlfrk; it doesn't work. The script won't run.

BeefofAges
Jun 5, 2004

Cry 'Havoc!', and let slip the cows of war.

WickedMetalHead posted:

py2exe and py2app Will pack up a python program into a .exe and a .app. I've never personally used them but i do believe those are the standard for packing like that.

If you don't want to do that, you should be able to use something like easy_install to package your product up, and then have it list dependencies. This will then download the things they don't already have, and use the things they already have installed on their system.

Although im not sure if easy_install works in windows or Mac, i've only used it in Linux.

Will py2exe and py2app work for modules that aren't part of the standard Python install?

hlfrk414
Dec 31, 2008

darknife posted:

Well, I know that using the same name is not good practice. I don't do that. It was just an example where I messed up on the names.

And hlfrk; it doesn't work. The script won't run.

Ah, missed the next error in your code. You can't define a variable called guesses and then define a function called guesses as well. Well, you can, but it simply keeps the last assignment, which is assigning the function definition to the name guesses. Python can't tell the difference between the two (and for good reason.) So rename one or the other and it will work.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

darknife posted:

Well, I know that using the same name is not good practice. I don't do that. It was just an example where I messed up on the names.

And hlfrk; it doesn't work. The script won't run.

Don't rewrite your code and ask us to debug that. Put your code in (or use pastebin or something if it's too long) so we can help you out. No point introducing yet another layer of abstraction.

Bouquet
Jul 14, 2001

BeefofAges posted:

Will py2exe and py2app work for modules that aren't part of the standard Python install?
py2exe bundled up pyglet for me with no problem. It basically follows all the import statements and grabs things until there are no dependencies left. I am not sure about py2exe's ability to bundle things like icons/art assets/etc. I have not tried py2app, but I imagine it should be functionally pretty similar.

BeefofAges
Jun 5, 2004

Cry 'Havoc!', and let slip the cows of war.

Bouquet posted:

py2exe bundled up pyglet for me with no problem. It basically follows all the import statements and grabs things until there are no dependencies left. I am not sure about py2exe's ability to bundle things like icons/art assets/etc. I have not tried py2app, but I imagine it should be functionally pretty similar.

Great, I'll have to try them on Monday. My program doesn't have a gui, so I'm not concerned about art assets or anything like that.

epswing
Nov 4, 2003

Soiled Meat
Any nose users: I'm trying to import a module at runtime with __import__, I can make calls to the imported module (see m.hello()), but nose complains saying "OSError: No such file" when nose.runmodule() is executed.

code:
--- tests.py:
import sys, nose

module_path, sep, module_name = sys.argv[1].replace('/', '.').rpartition('.')
m = getattr(__import__(module_path, locals(), globals(), [module_name], -1), module_name)

def some_test():
	assert True == True
 
if __name__ == '__main__':
	print m.hello()
	nose.runmodule()

--- subdir/to/module.py:
def hello():
	return "Hello! The import worked!"

$ python tests.py subdir/to/module
Hello! The import worked!
Traceback (most recent call last):
  File "/var/lib/python-support/python2.5/nose/failure.py", line 29, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file /home/myname/subdir/to/module
e: No error is produced if nose.runmodule() is commented out.

epswing fucked around with this message at 21:41 on Mar 28, 2009

king_kilr
May 25, 2007
For those curious as to why PyCon is the best conference ever, or wanting to see just what Mr. Monkeyz is up to: http://pycon.blip.tv/#1940650

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

epswing posted:

:words:

Hi. :v:

Anyway, I stepped through nose.runmodule() with pdb to find out what was going on. The issue is that you have something in the argv; run the script passing no arguments and it'll work just fine. Nose is examining the argv and doing something with it.

BeefofAges posted:

Will py2exe and py2app work for modules that aren't part of the standard Python install?

py2app does, anyway. It even rewrites all of the python extension modules and the dylibs they depend on using macholib to make sure they work in the app bundle. It's pretty crazy.

You might also have to use macports to install the development version of macholib, because the version that comes bundled on 10.5 isn't new enough for some dylibs.

darknife posted:

:words:

Also note that checking == True or == False is not only redundant, but can lead to false negatives.

epswing
Nov 4, 2003

Soiled Meat

Habnabit posted:

Hi. :v:

Anyway, I stepped through nose.runmodule() with pdb to find out what was going on. The issue is that you have something in the argv; run the script passing no arguments and it'll work just fine. Nose is examining the argv and doing something with it.

Thanks for taking a look, I appreciate it. :)

Edit: Ahaha I just got the ":v:" The nose guys might say something, if anyone's interested http://code.google.com/p/python-nose/issues/detail?id=247

Of course there's something in argv, I want to load an argv-specified module at runtime, that's the point :colbert: So...what can I do here. Maybe clean out argv (if it's modifiable?) before it hits nose.runmodule()?

Thanks again.

epswing fucked around with this message at 16:18 on Mar 29, 2009

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
I'm having an odd problem with IPython: the colors that it uses to print up code (in error and introspection) are unreadable in my terminal. So at first I did the usual - edited my settings in .ipython/ipytonrc. This had no effect. After some investigation, I find that you're now supposed to use .ipython/ipy_user_conf.py. Fine, edit that. Still has no effect. I'm baffled at this point. Any idea where I can look for or change the setting?

Kire
Aug 25, 2006
I have an issue with getting Tkinter to execute a command on clicking a button widget:

code:
from Tkinter import *

def events(item):
    print 'Today, %s happened' % (item)

win = Tk()
win.title('April')


day1 = Button(win, text='1', anchor=SE, activebackground="#fff", \
              command=events('bday'), relief="groove")
day1.grid(ipadx=3, ipady=3)


day2 = Button(win, text='2', anchor=SE, activebackground="#fff", \
              command=events('occurence'), relief="groove")
day2.grid(column=1, row=0, ipadx=3, ipady=3)
When I run it, it will print "Today bday happened" "Today occurence happened" and then the button for day1 or day2 won't print the message again when i press it, they just go dead and don't call the function. I don't want it to print anything when the program is run until the buttons are pressed, and then I want it to print the appropriate message. What's the issue?

Modern Pragmatist
Aug 20, 2008

Kire posted:

When I run it, it will print "Today bday happened" "Today occurence happened" and then the button for day1 or day2 won't print the message again when i press it, they just go dead and don't call the function. I don't want it to print anything when the program is run until the buttons are pressed, and then I want it to print the appropriate message. What's the issue?

code:
from Tkinter import *

def events(item):
    print 'Today, %s happened' % (item)

win = Tk()
win.title('April')


day1 = Button(win, text='1', anchor=SE, activebackground="#fff", \
              command=lambda:events('bday'), relief="groove")
day1.grid(ipadx=3, ipady=3)


day2 = Button(win, text='2', anchor=SE, activebackground="#fff", \
              command=lambda: events('occurence'), relief="groove")
day2.grid(column=1, row=0, ipadx=3, ipady=3)

win.mainloop()
Note the use of lambda function when setting the callback for the buttons. What was happening was it was executing the callback when assigning it.

Also, you have to use win.mainloop() to allow the application to remain open and listen for events.

BeefofAges
Jun 5, 2004

Cry 'Havoc!', and let slip the cows of war.

Is anyone familiar with this error?
code:
UnicodeError: \N escapes not supported (can't load unicodedata module)
I'm trying to use Python 2.5.4 in Vista 64 and it gives me this error whenever I try to run a script. When I googled, all I found was discussion of alternate ways to build Python, but I'm not sure how to do that. I'm just installing from an msi.

(Before you ask why I'm using 2.5 and not 2.6, it's so that I can use matplotlib, which only supports 2.5)

BeefofAges fucked around with this message at 07:44 on Apr 1, 2009

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

BeefofAges posted:

Is anyone familiar with this error?
code:
UnicodeError: \N escapes not supported (can't load unicodedata module)
I'm trying to use Python 2.5.4 in Vista 64 and it gives me this error whenever I try to run a script. When I googled, all I found was discussion of alternate ways to build Python, but I'm not sure how to do that. I'm just installing from an msi.

(Before you ask why I'm using 2.5 and not 2.6, it's so that I can use matplotlib, which only supports 2.5)

matplotlib works just fine for me on 2.6. Maybe it's that there's only binaries for up to 2.5.

Kire
Aug 25, 2006

Modern Pragmatist posted:

code:
from Tkinter import *

def events(item):
    print 'Today, %s happened' % (item)

win = Tk()
win.title('April')


day1 = Button(win, text='1', anchor=SE, activebackground="#fff", \
              command=lambda:events('bday'), relief="groove")
day1.grid(ipadx=3, ipady=3)


day2 = Button(win, text='2', anchor=SE, activebackground="#fff", \
              command=lambda: events('occurence'), relief="groove")
day2.grid(column=1, row=0, ipadx=3, ipady=3)

win.mainloop()
Note the use of lambda function when setting the callback for the buttons. What was happening was it was executing the callback when assigning it.

Also, you have to use win.mainloop() to allow the application to remain open and listen for events.

Thanks, that worked.

Ethereal
Mar 8, 2003
I'm trying to do some basic socket programming using Python 2.6. The data being sent is a simple string from an embedded device I'm working on. When I run the following code though, it only prints "Let's get this party started right...", and doesn't show the rest of the debug prints. When I hit Control+C to break the program, it then prints out the next two lines...what the hell is going on? (Run on Mac OS X)

code:
#! /usr/bin/env python

import socket
import sys

host = "192.168.1.141"
port = 21667
bufferSize = 1024
addr = (host, port)
s = None

#Create the socket and bind it to our address
print "Let's get this party started right..."



try:
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # create a TCP connection
except socket.error,msg:
	print "Error creating socket...",msg,
	s = None
	
if s is None:
	print 'Could not open socket...'
	sys.exit(1)
	

print "Binding address...'",
s.bind(addr) #bind to our host and port

print "Listening for a connection...",
s.listen(1); #Allow 1 connection at a time

#wait for the next client
connection, address = s.accept()  # connection is our actual socket
while 1: # receive data until we're done
	data = connection.recv(bufferSize) #receive our data in buf sized chunks
	if data: # we received all the data
		#do some formatting here
		#write to mysql
		print data,
	
	break
connection.close()	# we've finished with this packet

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
Take the commas off the ends of your print statements, they don't belong there.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

fge posted:

Take the commas off the ends of your print statements, they don't belong there.

what if he doesn't want newlines with his prints?

if that is a direct copy paste,
s.listen(1); <--- that may be acting weird, but I am not sure.

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again

deimos posted:

what if he doesn't want newlines with his prints?

if that is a direct copy paste,
s.listen(1); <--- that may be acting weird, but I am not sure.

I'm running his code, and those print lines with the commas after them won't show up; they only print after the commas are removed. I'm pretty sure he needs to use sys.stdout.write() or whatever it is if he wants to print without a newline.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
Try calling sys.stdout.flush() after your print statements, perhaps your stdout's got some sort of auto-flush on newlines behavior.

fge posted:

Take the commas off the ends of your print statements, they don't belong there.

Commas just prevent newlines, they're fine.

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again

Janin posted:

Commas just prevent newlines, they're fine.

Yeah you're right. The commas work on my machine in a a different file, but not in his code for some reason. Weird.

Adbot
ADBOT LOVES YOU

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
I've been getting interested in Mono recently - I'm primarily OSX and Linux so the Windows-bound .Net just wasn't any good - and so I begane to wonder what the situation is with Python and Mono / etc. This means IronPython, yes? And can I run IronPython on a non-Windows platform? Their site didn't help me in answering this.

  • Locked thread