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
spankweasel
Jan 4, 2006

I will tell you from experience that upgrading python versions in an OS distribution is a -nightmare-. We upgraded from python 2.4 to 2.6 and, even with 2 months of lead time for all the projects using python to set themselves straight with 2.6, everything completely broke for a number of OS builds. It took a couple of additional weeks to straighten everything out to people's satisfaction.

I highly doubt we'll upgrade to 2.7 unless there's a justifiable business reason to do so. New unittest.py functionality won't cut it. :v:

Adbot
ADBOT LOVES YOU

Lurchington
Jan 2, 2003

Forums Dragoon
Backport the new module into <2.7 using unittest2 from pypi :)

wins32767
Mar 16, 2007

The Journey Fraternity posted:

I'd consider myself privileged if I could use 2.5 at work. We're stuck with 2.3. :eng99:

At my last job (which I left in 2006) we were still using 1.3. Apparently it takes far too much time to test the migration to a new version. Mainly because we had to roll all of our own libraries for everything under the sun since we were so far behind the times.

m0nk3yz
Mar 13, 2002

Behold the power of cheese!
I'm lucky in that I can use any Python version I can compile and make the dependencies run on for the most part - but I go along with the OS vendor's version because I'm lazy, and I don't need everything in 2.7 right now. I'll be really happy when my biggest dependency (Django) has a Python 3 version that's blessed :)

Sylink
Apr 17, 2004

Say I wanted to write a python program that allowed arrow key/mouse input but sort of like an old DOS program would. Is there support for input/output at a basic level?

Sort of like being able to recreate vi editor in python is the closest example I can think of.

Or do I have to either go with basic input functions asking questions or full GUI?

BeefofAges
Jun 5, 2004

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

Sylink posted:

Say I wanted to write a python program that allowed arrow key/mouse input but sort of like an old DOS program would. Is there support for input/output at a basic level?

Sort of like being able to recreate vi editor in python is the closest example I can think of.

Or do I have to either go with basic input functions asking questions or full GUI?

If you use tkinter (or another GUI toolkit) you can capture keyboard events. I think that might be the most reasonable way to do what you want.

Deus Rex
Mar 5, 2005

Sylink posted:

Say I wanted to write a python program that allowed arrow key/mouse input but sort of like an old DOS program would. Is there support for input/output at a basic level?

Sort of like being able to recreate vi editor in python is the closest example I can think of.

Or do I have to either go with basic input functions asking questions or full GUI?

if you're working in a CLI, you could use curses

BeefofAges
Jun 5, 2004

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

Deus Rex posted:

if you're working in a CLI, you could use curses

Not in Windows, though :(

Sylink
Apr 17, 2004

I need to work in Windows, otherwise that would be cool. I'll have to play with tkinter then.

EDIT: though it says curses works in DOS and you can run python through the Windows command line anyway so would it work?

BeefofAges
Jun 5, 2004

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

Sylink posted:

I need to work in Windows, otherwise that would be cool. I'll have to play with tkinter then.

EDIT: though it says curses works in DOS and you can run python through the Windows command line anyway so would it work?

code:
C:\Python26>python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\curses\__init__.py", line 15, in <module>
    from _curses import *
ImportError: No module named _curses
>>>
This is in Vista.

Captain Capacitor
Jan 21, 2008

The code you say?

BeefofAges posted:

code:
C:\Python26>python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\curses\__init__.py", line 15, in <module>
    from _curses import *
ImportError: No module named _curses
>>>
This is in Vista.

Curses: Foiled again!

(Couldn't resist.)

Sylink
Apr 17, 2004

Some person made a port for Windows, I'll have to try it later.

http://adamv.com/dev/python/curses/

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.
Way nicer than using curses directly is using urwid. It has a curses backend, so it's compatible with wcurses. I've also written an UrwidProtocol for twisted so you serve up console-based applications over telnet or whatever. curses can't do that!

Kolodny
Jul 10, 2010

Quick question: how do I search a string with the origin on the right? find and rfind search from l to r and r to l respectively, but both have the origin on the left.

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Kolodny posted:

Quick question: how do I search a string with the origin on the right? find and rfind search from l to r and r to l respectively, but both have the origin on the left.

>>> 'abcde'[::-1].startswith('edc')
True

Lurchington
Jan 2, 2003

Forums Dragoon
I don't know if I'm misreading what you want, but I think flipping the string and your search query would cause me to make a mistake. Especially since there is an endswith() method:

code:
>>> 'abcde'.endswith('cde')
    True

BeefofAges
Jun 5, 2004

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

reversed() might also be handy for this.

qntm
Jun 17, 2009
How is image manipulation done in Python 3? What module should I use?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Are you the same qntm from qntm.org? I ask because if you are, we have two posters named Sam Hughes, which is kinda :2bong:

qntm
Jun 17, 2009

Otto Skorzeny posted:

Are you the same qntm from qntm.org? I ask because if you are, we have two posters named Sam Hughes, which is kinda :2bong:

Yes I am, and yes I know. We actually met online a few years ago. I think we decided that I was the evil one because I have the goatee.

ChiralCondensate
Nov 13, 2007

what is that man doing to his colour palette?
Grimey Drawer

qntm posted:

How is image manipulation done in Python 3? What module should I use?
PIL is pretty much standard, and is pretty nice to work with to boot.

Edit: sorry, glossed over you saying Python 3. I think PIL for Py3 is still in the pipeline.

Kolodny
Jul 10, 2010

code:
>>> a = ['bbb','ccc','axx','xzz','xaa']
>>> i=0
>>> for s in a:
...   if s[0]!='x':
...     del a[i]
...   i = i+1
...
>>> a
['ccc', 'xzz', 'xaa']
Does anyone know why a[0]='ccc' ?

Threep
Apr 1, 2006

It's kind of a long story.

Kolodny posted:

code:
>>> a = ['bbb','ccc','axx','xzz','xaa']
>>> i=0
>>> for s in a:
...   if s[0]!='x':
...     del a[i]
...   i = i+1
...
>>> a
['ccc', 'xzz', 'xaa']
Does anyone know why a[0]='ccc' ?
First off, use enumerate for a construct like that:
code:
>>> a = ['bbb','ccc','axx','xzz','xaa']
>>> for i, s in enumerate(a):
...   if s[0]!='x':
...     del a[i]
...
>>> a
['ccc', 'xzz', 'xaa']
Secondly and more importantly, don't delete from a list while iterating it. It makes weird things happen, as you saw. Here's a better solution:
code:
>>> a = ['bbb','ccc','axx','xzz','xaa']
>>> [s for s in a if s[0] != 'x']
['bbb', 'ccc', 'axx']

xPanda
Feb 6, 2003

Was that me or the door?
Does anyone know why there are only pre-compiled versions of NumPy 1.5.0 for Python3.1 available for only win32, and not OSX? A cursory google reveals nothing and I don't like the idea of having to try and compile it myself.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
NumPy is pretty trivial to compile on OS X.

Lurchington
Jan 2, 2003

Forums Dragoon
a lot of people I work with use (darwin)port(s) to do their OSX python-wrangling, and so far I only see py2.6 and earlier version. That's normally my suggestion for this kind of thing though.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!
I've been using homebrew for my OS X package management for a while. It's a pretty nice piece of work.

Sylink
Apr 17, 2004

Has anyone here used mod_python?

I'm trying to use it with the publisher handle and I can't get it to work right, the server pages come as not found on a Fedora server.

I know it kind of works because this yields a result if I have handler mptest.py

code:
<Directory /some/path>
    SetHandler mod_python 
    PythonHandler mptest
    PythonDebug On
</Directory>

But this doesnt work
code:
<Directory /some/path>
    SetHandler mod_python 
    PythonHandler mod_python.publisher
    PythonDebug On
</Directory>
EDIT: Nevermind I'm an idiot and needed to add an index function.

Sylink fucked around with this message at 16:38 on Sep 8, 2010

Threep
Apr 1, 2006

It's kind of a long story.

Sylink posted:

Has anyone here used mod_python?
I hate to sound like a broken record, but are you sure you should be using mod_python? I've yet to find a use case where it's preferable to mod_wsgi, and it's the source of so many problems.

Sylink
Apr 17, 2004

I'm just playing with it.

I'll be abandoning python for this project anyway. The web applications are weird as gently caress compared to the standard php/mysql.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Use django with its built in web server. It's the easiest thing to setup for playing around and doesn't require any fidling with apache.

Threep
Apr 1, 2006

It's kind of a long story.

Sylink posted:

I'm just playing with it.

I'll be abandoning python for this project anyway. The web applications are weird as gently caress compared to the standard php/mysql.
In that case, first of all, mod_python is a red herring. I made that mistake too, if you're coming from mod_php it sounds like the obvious choice.

Most Python web frameworks are MVC-based like the big PHP frameworks, but there's some that can be used like simple PHP pages, although I can't think of any names off hand.

The reason for that is that, trust me on this, if you spend the 10 mins necessary to learn the basics of Django. As mentioned above, you can use the built in webserver and get started with playing around with it immediately. And once you do want it installed, mod_wsgi is much easier to get running on Apache than mod_python.

I came from PHP and terrible web programming practices and Django seemed strange as gently caress, but it takes very little time working with it to realize how much better it is.

king_kilr
May 25, 2007

Sylink posted:

I'm just playing with it.

I'll be abandoning python for this project anyway. The web applications are weird as gently caress compared to the standard php/mysql.

We're very sorry that we have something that looks less like spaghetti and more like software engineering.

First Time Caller
Nov 1, 2004

king_kilr posted:

We're very sorry that we have something that looks less like spaghetti and more like software engineering.

PHP MVC Frameworks aren't bad. Get off your high horse.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

First Time Caller posted:

PHP MVC Frameworks aren't bad. Get off your high horse.

He never mentioned them being bad, the OP said

quote:

The web applications are weird as gently caress compared to the standard php/mysql.
which usually means a jumbled mess of spaghetti code.

Beseiged
Aug 27, 2007

Random Text Under A Picture
I'd like to use something that is sorta like JavaDoc. Does anyone have any recommendations for tools they like to use?

b0lt
Apr 29, 2005

Beseiged posted:

I'd like to use something that is sorta like JavaDoc. Does anyone have any recommendations for tools they like to use?

Sphinx.

BeefofAges
Jun 5, 2004

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

Beseiged posted:

I'd like to use something that is sorta like JavaDoc. Does anyone have any recommendations for tools they like to use?

We use Doxygen at my office.

MelonWheels
May 24, 2004
The ending of Max Payne 2 made me cry.
I'm new to to programming, so this an general advice question. My first language a few months ago was python, and I quite like it. However, in some instances it seems to run slow, so I'm learning C now. What I wonder is: is it worth it to mix the two languages with the Python/C API (or Cython) in order to get more speed and mix languages, or will I just create some putrid pile of crap? Do people write C extensions just for quicker code execution, or am I missing the point?

Adbot
ADBOT LOVES YOU

Dijkstracula
Mar 18, 2003

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

So...as a relatively hardcore Perl dork, I have to say that I'm rather enjoying Python these days. :)

That said:

The first page of the megathread mentions some alternative APIs that offer threads that span more than one CPU. Are they still the choices of today or has something else/better come along? I am sadly hitting 101% CPU utilization with my current implementation :(

  • Locked thread