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
Sock on a Fish
Jul 17, 2004

What if that thing I said?
How do you get around smtplib.sendmail stripping whitespace characters from the To: and From: header lines?

All I've found is this mailing list conversation which just tells me that this apparently compliant with the RFC but offers no tips on getting around it. I've tried encoding the strings in Unicode, and making them an email.Header class, but it's no good. I've looked through smtplib but can't figure out where it's stripping out these spaces.

Adbot
ADBOT LOVES YOU

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

wrok posted:

This is the zen of Stackless really. When I started using it I thought I understood this, and knew what I was doing, until I found my program deadlocked (or so I thought). It quickly dawned on me (like a ton of bricks) that there is only explicit yielding and never preemptive yielding (unless you make it so). In that moment I became Stackless enlightened.

You know, I thought I'd dreg this back up - right now I have the stackless code open on my bench - I'm digging through it for my pycon talk (I just finished twisted) and while it's pretty cool, and sure - cooperative multitasking and event/message passing is cool - jesus this can get crazy.

That being said, from an end user standpoint, it's pretty simple when you think about it - yield control when you don't need it, and communicate via messages/events. Although right now, I prefer the ease of using Kamaelia :)

wrok
Mar 24, 2006

by angerbotSD

m0nk3yz posted:

You know, I thought I'd dreg this back up - right now I have the stackless code open on my bench - I'm digging through it for my pycon talk (I just finished twisted) and while it's pretty cool, and sure - cooperative multitasking and event/message passing is cool - jesus this can get crazy.

That being said, from an end user standpoint, it's pretty simple when you think about it - yield control when you don't need it, and communicate via messages/events. Although right now, I prefer the ease of using Kamaelia :)

Yeah, the more I work with it, the more I realize that the building blocks it offers (tasklets and channels) really need to be pretty well wrapped up in a framework for your application to take advantage of them while avoiding some crazyness. Less so for tasklets, more so for channels.

What's Kamaelia give you? Just ease of use? I've only briefly glanced at it. :)

tripwire
Nov 19, 2004

        ghost flow
Everyone who likes python for legibility but has concerns about performance should check out codepy, here: http://mathema.tician.de/software/codepy

It uses boost python or pycuda to compile and link python strings as C code (and run it on the GPU if you are using pycuda). I think this might be really useful for a lot of people.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

wrok posted:

Yeah, the more I work with it, the more I realize that the building blocks it offers (tasklets and channels) really need to be pretty well wrapped up in a framework for your application to take advantage of them while avoiding some crazyness. Less so for tasklets, more so for channels.

What's Kamaelia give you? Just ease of use? I've only briefly glanced at it. :)

Kamaelia (or Axon rather) give you the framework, and it's pretty damned simple to use.
http://jessenoller.com/2009/01/29/a-gentle-overview-of-kamaelia-or-its-axon-stupid/

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

tripwire posted:

Everyone who likes python for legibility but has concerns about performance should check out codepy, here: http://mathema.tician.de/software/codepy

It uses boost python or pycuda to compile and link python strings as C code (and run it on the GPU if you are using pycuda). I think this might be really useful for a lot of people.

I prefer Cython (http://www.cython.org/) personally, but I don't know how much the two overlap

tripwire
Nov 19, 2004

        ghost flow

m0nk3yz posted:

I prefer Cython (http://www.cython.org/) personally, but I don't know how much the two overlap

I guess they aren't too far apart, codepy just looks nice because you can build your code and compile + link it on the fly (i.e. have dynamically generated code), you don't have to dick around with makefiles and all that basically.

king_kilr
May 25, 2007

tripwire posted:

I guess they aren't too far apart, codepy just looks nice because you can build your code and compile + link it on the fly (i.e. have dynamically generated code), you don't have to dick around with makefiles and all that basically.

Cython can do that with the pyimportx module that it includes from .11 on, it can even try to compile ordinary python code and fall back to the raw interpretter if it can't handle that.

Sock on a Fish
Jul 17, 2004

What if that thing I said?

Sock on a Fish posted:

How do you get around smtplib.sendmail stripping whitespace characters from the To: and From: header lines?

All I've found is this mailing list conversation which just tells me that this apparently compliant with the RFC but offers no tips on getting around it. I've tried encoding the strings in Unicode, and making them an email.Header class, but it's no good. I've looked through smtplib but can't figure out where it's stripping out these spaces.

Figured this one out -- it wasn't Python, it was Gmail. If you don't include the '<address@domain.com>' at the end of the From and To strings it strips out all the spaces. I don't know why!

Modern Pragmatist
Aug 20, 2008

Sock on a Fish posted:

If you don't include the '<address@domain.com>' at the end of the From and To strings it strips out all the spaces. I don't know why!

Just curious about this, could you post a string that would be affected by what you were talking about?

Sock on a Fish
Jul 17, 2004

What if that thing I said?

Modern Pragmatist posted:

Just curious about this, could you post a string that would be affected by what you were talking about?

Any string with a space in it without the address contained between '<' and '>'. For example, 'Bootsy Collins'. I'm not sure if the relevant spec requires the address to be specified in the From: header, but not specifying it doesn't cause odd behavior like this in other email clients.

Modern Pragmatist
Aug 20, 2008

Sock on a Fish posted:

Any string with a space in it without the address contained between '<' and '>'. For example, 'Bootsy Collins'. I'm not sure if the relevant spec requires the address to be specified in the From: header, but not specifying it doesn't cause odd behavior like this in other email clients.

My guess is that it just ensuring that you indeed are entering an email address into the From and To headers because I believe that the standard way to have a display name and email is:

John Smith <john.smith@example.com>

and if you just had "John Smith" it would attempt to make it into an email address and strip any whitespace characters (since spaces are not allowed in email addresses).

john.smith@example.com, john.doe@example.com

Doesn't contain < or > but when the whitespaces are removed it would be interpreted correctly.

Also, I believe that an address (even if it is not a valid address) has to be displayed in both the To and From.

Feel free to correct me if I am misunderstanding at all.

Modern Pragmatist fucked around with this message at 01:11 on Feb 12, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Just to bring a question I had from the general programming thread to here:

Caveat: I am not a Pythoner; I have not written one line of Python. :)

I'm looking at using SciPy for a computational differential equations class project this term, as I'd like to use a real programming language rather than Matlab for at least part of the course. I'm curious about the performance of SciPy as opposed to the traditional Fortran/C LAPACK/BLAS approach. In real-world scientific apps that are written in Python (of which was told in the other thread that there are many), do they link against an existing library (be it Atlas, MKL, BLAS, or whatever, assuming that this is possible), or are the critical parts of SciPy not interpreted code, or..?

tripwire
Nov 19, 2004

        ghost flow

Dijkstracula posted:

Just to bring a question I had from the general programming thread to here:

Caveat: I am not a Pythoner; I have not written one line of Python. :)

I'm looking at using SciPy for a computational differential equations class project this term, as I'd like to use a real programming language rather than Matlab for at least part of the course. I'm curious about the performance of SciPy as opposed to the traditional Fortran/C LAPACK/BLAS approach. In real-world scientific apps that are written in Python (of which was told in the other thread that there are many), do they link against an existing library (be it Atlas, MKL, BLAS, or whatever, assuming that this is possible), or are the critical parts of SciPy not interpreted code, or..?
Numpy (part of the scipy project) lets you use the traditional fortran LAPACK/BLAS libraries anyway and the arrays are a thin wrapper around c arrays, so performance-wise its really not too shabby.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!
Oh god, I tried to grok twisted. http://jessenoller.com/2009/02/11/twisted-hello-asynchronous-programming/

wrok
Mar 24, 2006

by angerbotSD

Dijkstracula posted:

Just to bring a question I had from the general programming thread to here:

Caveat: I am not a Pythoner; I have not written one line of Python. :)

I'm looking at using SciPy for a computational differential equations class project this term, as I'd like to use a real programming language rather than Matlab for at least part of the course. I'm curious about the performance of SciPy as opposed to the traditional Fortran/C LAPACK/BLAS approach. In real-world scientific apps that are written in Python (of which was told in the other thread that there are many), do they link against an existing library (be it Atlas, MKL, BLAS, or whatever, assuming that this is possible), or are the critical parts of SciPy not interpreted code, or..?

Check out SAGE. Who knows if it's something you'd be interested in, but to a non-math person it seems like it would be. As they state on the webpage it's a Python based system with the goal of "creating a viable free open source alternative to Magma, Maple, Mathematica and Matlab."

There's even a web interface, so you don't necessarily need to run it locally. Pretty nifty (And pretty much a silver bullet for Project Euler problems if you're into that kind of thing).

tef
May 30, 2004

-> some l-system crap ->
Has anyone used cinpy: http://www.cs.tut.fi/~ask/cinpy/

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

tripwire posted:

Numpy (part of the scipy project) lets you use the traditional fortran LAPACK/BLAS libraries anyway and the arrays are a thin wrapper around c arrays, so performance-wise its really not too shabby.
Excellent, thanks for this. I'll definitely pursue scipy further, then.

wrok posted:

Check out SAGE.
Woah, this looks very cool. Thanks :)

politicorific
Sep 15, 2007
I want to check the last character of a string, and if it matches my condition, I want to replace it with a specific character, but only the end character, not anything in the middle.

code:
def check():
    a = "reader"
    if a[-1:]=="r":
        a=a[0:-1]
        a=a+"R"
Each character has a single mapping, so that r=R, s=S, p=V, ect, only once.

Rather than make hundreds of copies of this code, specifying each condition, how can I do this elegantly? I'd like to learn and grow my skills.

tef
May 30, 2004

-> some l-system crap ->

politicorific posted:


code:
def check():
    a = "reader"
    if a[-1:]=="r":
        a=a[0:-1]
        a=a+"R"

code:
>>> transform = { 'a' : 'B' }
>>> def check(foo):
...     if foo[-1] in transform:
...             foo = foo[0:-1]+transform[foo[-1]]
...     return foo
... 
>>> print check("toota")
tootB
>>> 

bitprophet
Jul 22, 2004
Taco Defender

m0nk3yz posted:

Oh god, I tried to grok twisted. http://jessenoller.com/2009/02/11/twisted-hello-asynchronous-programming/

Sup learning-Twisted buddy :):hf::) Thanks for the article (and especially the links at the end. Delicious, tasty links)! I think it's neat you were talking to Glyph about it, and how that resulted in that peek at the "advanced" usage of the decorator/generator stuff.

Also, I know you tend to complain that users bitch about the length of your articles, but I thought this one was pretty on the mark. Many tutorials/articles are shorter and would basically have been the first half of yours -- a high level overview and 1-2 simple examples. But then you went a bit deeper and gave a good idea of not only what's possible at the basic level, but what lies beyond that. (And it wasn't so long as to get dreary ;))

ekalb
Jun 5, 2004
I'm wondering if there's a way to specify a directory in the py2exe setup file to store some of the .dll's and .pyd's that are copied when the executable is created. I've poked around in the py2exe documentation and haven't found anything helpful...

sw-itch
Apr 6, 2008

ekalb posted:

I'm wondering if there's a way to specify a directory in the py2exe setup file to store some of the .dll's and .pyd's that are copied when the executable is created. I've poked around in the py2exe documentation and haven't found anything helpful...

code:
options['zipfile'] = 'lib/library.zip'
Add that to the options and the .pyd's will follow the zip that is created, not sure if the dll's can be moved. 'lib' and 'library' can be changed to whatever you wish.

ekalb
Jun 5, 2004

sw-itch posted:

code:
options['zipfile'] = 'lib/library.zip'
Add that to the options and the .pyd's will follow the zip that is created, not sure if the dll's can be moved. 'lib' and 'library' can be changed to whatever you wish.

Thanks! I feel silly for not thinking of being able to prepend a directory to that :-/... I also just found the following below to be helpful in case anyone else is wondering the same thing as I was.

http://www.py2exe.org/index.cgi/SingleFileExecutable

politicorific
Sep 15, 2007

tef posted:

code:
awesome working code
Thank you, took me a little while to make it work with unicode, but hooray - reusable code!

Next question, how do I return on a value? Python docs say "a bare return indicates that the generator is done and will cause StopIteration to be raised."
code:
>>> mv = "here is a string"
>>> mcv = ("a","e","i","o","u")
>>> def stripvowels(foo,bar):
...	for x in bar:
...		if x in foo:
...			foo = foo.replace(x,'')
...			print foo			
>>> stripvowels(mv,mcv)
here is  string
hr is  string
hr s  strng
if I add "return foo" after the "print foo" line, I get:
code:
>>> stripvowels(mv,mcv)
here is  string
'here is  string'
>>> 
How do I return this?

deimos
Nov 30, 2006

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

politicorific posted:

Thank you, took me a little while to make it work with unicode, but hooray - reusable code!

Next question, how do I return on a value? Python docs say "a bare return indicates that the generator is done and will cause StopIteration to be raised."
code:
>>> mv = "here is a string"
>>> mcv = ("a","e","i","o","u")
>>> def stripvowels(foo,bar):
...	for x in bar:
...		if x in foo:
...			foo = foo.replace(x,'')
...			print foo			
>>> stripvowels(mv,mcv)
here is  string
hr is  string
hr s  strng
if I add "return foo" after the "print foo" line, I get:
code:
>>> stripvowels(mv,mcv)
here is  string
'here is  string'
>>> 
How do I return this?

code:
>>> mv = "here is a string"
>>> mcv = ("a","e","i","o","u")
>>> def stripvowels(foo,bar):
...	for x in bar:
...		if x in foo:
...			foo = foo.replace(x,'')
...			print foo
...	return foo
...
>>> stripvowels(mv,mcv)
here is  string
hr is  string
hr s  strng
'hr s  strng'
The last one is the return value.

tef
May 30, 2004

-> some l-system crap ->
There are two types of functions at work here: plain functions and generators.

A generator is a function you can call repeatedly to get new results:

code:
>>> def expr(foo):
...     for bar in foo:
...             yield bar
... 
>>> for thing in expr("hello"):
...     print thing
... 
h
e
l
l
o
Here expr is a generator - it uses the yield keyword. yield means 'return, but come back here' in python.

code:
>>> expr
<function expr at 0xb7d6c41c>
>>> expr("toot")
<generator object at 0xb7d77d6c>
Notice how if we call expr normally, we get a generator. this is why we use the for statement above, to go through all the values.

We can even call the generator manually
code:
>>> g = expr("toot")
>>> g.next()
't'
>>> g.next()
'o'
But normally we use for foo in generator() to iterate over the results.
There are a bunch of other cool things about generators

politicorific
Sep 15, 2007

deimos posted:

The last one is the return value.
Ah, I was trying to change the variable outside the function without the use of globals or classes... trying to hammer this all back inside my head.

deimos
Nov 30, 2006

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

politicorific posted:

Ah, I was trying to change the variable outside the function without the use of globals or classes... trying to hammer this all back inside my head.

Ack I was in a rush and answered just part of the question without going further into it, please read tef's post above and make sure you understand what a generator is and what it does.

shaitan
Mar 8, 2004
g.d.m.f.s.o.b.

Inverness posted:

I recommend any new to Python to start learning with version 2.6, as it is bridging the gap between Python 2 and 3.

Old quote, but this is why I came into the thread, why start with 2.6 when 3.0 is already out?

I've been interested in learning python for a while now, I would only be writing stuff for myself so I don't care about other people being compatible with what I write. Would starting off at 3.0 be reasonable?

tripwire
Nov 19, 2004

        ghost flow

shaitan posted:

Old quote, but this is why I came into the thread, why start with 2.6 when 3.0 is already out?

I've been interested in learning python for a while now, I would only be writing stuff for myself so I don't care about other people being compatible with what I write. Would starting off at 3.0 be reasonable?

Knock yourself out, but 9/10 of the usefulness of python is the huge library of modules available for it, almost none of which are ported to python 3.0 yet. Thats the main reason to stick with 2.6 as far as I can see.

shaitan
Mar 8, 2004
g.d.m.f.s.o.b.

tripwire posted:

Knock yourself out, but 9/10 of the usefulness of python is the huge library of modules available for it, almost none of which are ported to python 3.0 yet. Thats the main reason to stick with 2.6 as far as I can see.

ahh, I wasn't thinking of compatibility in that sense. That makes a pretty good argument for sticking with 2.6. Thanks!

bitprophet
Jul 22, 2004
Taco Defender

shaitan posted:

ahh, I wasn't thinking of compatibility in that sense. That makes a pretty good argument for sticking with 2.6. Thanks!

The other big reason is that 2.6 has as many of the new features/changes from 3.0 as is possible without actually breaking backwards compat, so it's sort of like 3.0 Lite in that sense.

as opposed to 2.4 or 2.5 which us existing Pythonistas writing software for wide consumption have to support and thus we don't get to play with the new shinies :cry:

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
I've been using paster / eggs / setuptools for building modules for a while now: generate a skeleton with "paster create", use "python setup.py develop" while I'm working on it, and "python setup.py install" for deployment. Once in a while something strange happens when the install stage installs an old version of the module. It looks to be that it pulls an old copy out of the "build" or "dist" directories and uses that to install, even if the module has been updated or has a later version number. Has anyone seen this? I haven't discerned a pattern to explain it yet.

ndb
Aug 25, 2005

If I develop a python script in Windows, can I then run that script in a Linux environment?

I apologize if this is a dumb question, but I'm incredibly new to this language.

armchair
May 19, 2005

creak... creak... creak...

Clock Explosion posted:

If I develop a python script in Windows, can I then run that script in a Linux environment?

I apologize if this is a dumb question, but I'm incredibly new to this language.

That's the idea. So long as both platforms have all the required modules available and installed. OS stuff is in a module called "OS". If there are parts of code that have to be different depending on what you're running on you conditionally execute them with an 'if' and check the what OS you're using with the OS module.

http://docs.python.org/library/os.html

hey mom its 420
May 12, 2007

Depends on the script. If you write the script in a portable way, yeah. If not, well, no.
For instance, if you want your code to be more portable, don't hardcode paths and path separators (like blah\blah, because that is blah/blah on unixy systems) but use os.path and so on.
But generally, yes, you can do that. I'd suggest just writing the script first and then posting it here to get people's thoughts on how portable it is.

ndb
Aug 25, 2005

Bonus posted:

Depends on the script. If you write the script in a portable way, yeah. If not, well, no.
For instance, if you want your code to be more portable, don't hardcode paths and path separators (like blah\blah, because that is blah/blah on unixy systems) but use os.path and so on.
But generally, yes, you can do that. I'd suggest just writing the script first and then posting it here to get people's thoughts on how portable it is.

That's what I thought. I'm going to do some more research before hand about it, just to be sure.

If any code comes out of it, I'll post it to get a good grasps on portability.

Thanks!

Jo
Jan 24, 2005

:allears:
Soiled Meat

Modern Pragmatist posted:

I am looking for a Python module that will allow me to generate 3D graphics but that allows a great deal of flexibility (more than visual seems to allow).

Basically what I want to do is be able to display an image or any other data in 3D space and allow the user to interact with it (rotation etc.)

Any suggestions would be appreciated.

I'm working on a 3D visualization system in Python using OpenGL. Send me a PM.

Adbot
ADBOT LOVES YOU

tripwire
Nov 19, 2004

        ghost flow

Jo posted:

I'm working on a 3D visualization system in Python using OpenGL. Send me a PM.

You too huh? Using pyopengl?

  • Locked thread