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
Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Tovarisch posted:

What was the main motivation for all the changes in Python 3.x?

I had problems installing matplotlib for 3.2, now having problems with ipython since it wants setuptools, which in turn are not available for 3.2. Half of the examples from the book I have don't work with 3.2 and require changes... I mean there should be some strong reasons for such dramatic changes, especially if the language is well established and already has a lot of supporters.

Someone can get into it more than this, but it cleaned up some...inconsistencies...in the syntax for one thing. That by itself probably isn't worth breaking everyone's poo poo except for the fact that you can (and it's usually recommended to) keep using 2.x instead of 3.2

Adbot
ADBOT LOVES YOU

No Safe Word
Feb 26, 2005

Tovarisch posted:

What was the main motivation for all the changes in Python 3.x?

Cutting the cord with stupid language decisions for the most part.

Then again, some in the reverse direction as well depending on your point of view :v:

OnceIWasAnOstrich
Jul 22, 2006

No Safe Word posted:

Cutting the cord with stupid language decisions for the most part.


The main thing really is that they kept adding new better ways to do things (think iterators instead of lists, division, less arbitrary comparison between types, unicode) and leaving the old ways just makes everything more confusing for people learning Python when they see things like 1/2=0 and they learn to do everything with lists instead of iterables. Basically there are a couple of different ways to do a lot of things, which really is counter to Python's stated goals. A number of these things will break a lot of people's code, so they just decided to do it all at once instead of breaking things bit by bit over many point releases.

2to3 of course is terrible, and universal unicode is a giant mess (ever try matching regular expressions to unicode categories?) so unless you are developing something from scratch that doesn't involve anything that is designed for python2 and you never want to run on python2, python3 is a pain in the rear end.

OnceIWasAnOstrich fucked around with this message at 00:00 on Apr 18, 2012

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
The intent was to clean up junk. They did a decent job in some places: some of the new IO stuff is nice, the Unicode cleanups were much needed (except for the lack of bytes.format). Unfortunately, we still have asyncore, and ABCs were a terrible idea in my opinion.

Catalyst-proof
May 11, 2011

better waste some time with you
Yeah, what the gently caress are ABCs?

tef
May 30, 2004

-> some l-system crap ->

Tovarisch posted:

I have numpy and scipy installed. Now looking for plotting library. Basically I am trying to replicate Matlab with Python...

http://www.sagemath.org/

Lurchington
Jan 2, 2003

Forums Dragoon

Fren posted:

Yeah, what the gently caress are ABCs?

abstract base classes

decent write-up:
http://www.doughellmann.com/PyMOTW/abc/

quote:

Why use Abstract Base Classes?

Abstract base classes are a form of interface checking more strict than individual hasattr() checks for particular methods. By defining an abstract base class, you can define a common API for a set of subclasses. This capability is especially useful in situations where a third-party is going to provide implementations, such as with plugins to an application, but can also aid you when working on a large team or with a large code-base where keeping all classes in your head at the same time is difficult or not possible.

in the event you knew what they were and just hate them, they added a bunch of awesome mixins to the collections module, and gently caress y'all that poo poo is awesome and useful:
http://docs.python.org/library/collections.html#collections-abstract-base-classes

Exergy
Jul 21, 2011


Thanks, it looks interesting. Using virtual machine may be somewhat inconvenient, but I will give it a try.

BigRedDot
Mar 6, 2008

ipython is amazing, I use it pretty much exclusively. Chaco and matplotlib are the two best plotting options I know of for python at the moment. Is there a particular reason you are using python 3?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Lurchington posted:

abstract base classes

decent write-up:
http://www.doughellmann.com/PyMOTW/abc/


in the event you knew what they were and just hate them, they added a bunch of awesome mixins to the collections module, and gently caress y'all that poo poo is awesome and useful:
http://docs.python.org/library/collections.html#collections-abstract-base-classes

The question ABCs allow you to ask is "is O a mutable sequence container?". The question should be "how do I get a mutable sequence container from O?". Instead of branching based on which one is it, provide a means to get what you want from what you have.

I can only think of one case where the question asked is a good one: serialization.

Lurchington
Jan 2, 2003

Forums Dragoon

Suspicious Dish posted:

The question ABCs allow you to ask is "is O a mutable sequence container?". The question should be "how do I get a mutable sequence container from O?". Instead of branching based on which one is it, provide a means to get what you want from what you have.

I can only think of one case where the question asked is a good one: serialization.

You're articulating your support for duck-typing, and that's totally fine. I happen to run into serialization-type tasks a bunch, so I do appreciate the isinstance(thing, collections.MutableSequence) support.

However, what I enjoy more (and referenced in my post) was the ability to subclass one of the collections types, getting a bunch of methods for free after only defining 2-3 base methods.

from the official docs:

quote:

Several of the ABCs are also useful as mixins that make it easier to develop classes supporting container APIs. For example, to write a class supporting the full Set API, it only necessary to supply the three underlying abstract methods: __contains__(), __iter__(), and __len__(). The ABC supplies the remaining methods such as __and__() and isdisjoint()
code:
class ListBasedSet(collections.Set):
     ''' Alternate set implementation favoring space over speed
         and not requiring the set elements to be hashable. '''
     def __init__(self, iterable):
         self.elements = lst = []
         for value in iterable:
             if value not in lst:
                 lst.append(value)
     def __iter__(self):
         return iter(self.elements)
     def __contains__(self, value):
         return value in self.elements
     def __len__(self):
         return len(self.elements)

s1 = ListBasedSet('abcdef')
s2 = ListBasedSet('defghi')
overlap = s1 & s2            # The __and__() method is supported automatically

always been useful for me

Lurchington fucked around with this message at 19:00 on Apr 18, 2012

vikingstrike
Sep 23, 2007

whats happening, captain
Looking to use some basic GUI tools in a program I'm writing. Never done any GUI programming and don't really have the energy to learn something very difficult. I've found easygui online and it looks to be pretty straight forward. Any opinions on easygui, or are there any better alternatives?

I guess that I could list some of the things I'm looking to do:
- Allow the user to use the normal OS X/Windows directory browser to choose a folder
- Allow the user to select certain items out a displayed list
- Capture basic strings from the user, like "name", "author", etc.

Well, it looks like EasyGUI doesn't allow basic poo poo like "I want the window size to be X", so yeah, I don't think this will work. Tkinter is in the standard library, which is nice. Is this the easiest way to go? Cross-platform compatibility and easy-of-use are important to me, but this may be a trade off type situation.

vikingstrike fucked around with this message at 19:08 on Apr 18, 2012

Exergy
Jul 21, 2011

BigRedDot posted:

Is there a particular reason you are using python 3?

Nope, after all pain with matplotlib and ipython (which I still was not able to install on 3.2 on Windows) I decided to downgrade to 2.7.

Spime Wrangler
Feb 23, 2003

Because we can.

If you have a .edu email account I highly recommend the enthought distro. It's the closest thing I've found in python to having matlab with a bunch of toolboxes. Single exe turnkey 2.7 with numpy/scipy/a ton of other useful stuff. Except no simulink. I would do some dumb poo poo to get a python replacement for simulink.

etcetera08
Sep 11, 2008

Popping in to say that IPython owns bones and Lurchington's posts on Python 3.x make me wanna start using it again ugggh port your poo poo, people.

Hed
Mar 31, 2004

Fun Shoe
Yeah matplotlib and Django are the only reasons I still work in 2.x. Granted those are still huge reasons, and 2.7 and 3.2 are quite similar but they are only going to start diverging more and more. I'm going to have to take another look at IPython, I remember back in 2006ish I had that set up and it was awesome.

xPanda
Feb 6, 2003

Was that me or the door?
The current git master of matplotlib seems to work with Python 3.2 for me, had no problems installing it and running some of the examples yesterday. I read that the upcoming 1.2 should support Python 3 natively (which is why the current head works). And yeah, ipython is pretty much essential.

On that note, with ipython is there some way to change the tab completion for more than a page of matches from More to something like Less, with supports scrolling back?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
More towards a general programming question, but:

So, I've ended up writing a CGI application. (Before someone jumps in, this isn't my choice, nor is it anything I can change. My colleagues I'm writing this for aren't in charge of their IT resources, they can only deploy a CGI app, I've got no way of changing that.) I'm using the Python WSGI stuff with a CGIHandler, which works fine, but development is a pain:

- in development, I can't use static assets (images, css files etc.)
- the webpage requests a favicon from the app, leading to spurious requests
- I could solve this all by actually developing in the cgi-bin directory, but I'm not eager

Any insights from people who have been down this path? It all seems more difficult than it should be.

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

Hed posted:

Yeah matplotlib and Django are the only reasons I still work in 2.x. Granted those are still huge reasons, and 2.7 and 3.2 are quite similar but they are only going to start diverging more and more. I'm going to have to take another look at IPython, I remember back in 2006ish I had that set up and it was awesome.

I was really against ipython for a really long while. I saw no reason to use it, as I was already using the IDLE interactive shell to test syntax and so forth as coding. I didn't think the ability to auto-load packages or to surf the directory structure while coding was worth it. What a fool I was!

I've really gotten to love ipython and while I don't use the auto-load feature, I love the ability to easily move around and do what I need to do.

My only real beef is that it's a pain in the rear end to reload a package when you find a bug. I wish there was a simple reset command that would completely erase all previously loaded poo poo... in a reliable way.

FoiledAgain
May 6, 2007

Anyone played with Python(x,y)? Is it worth the download?

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

JetsGuy posted:

I was really against ipython for a really long while. I saw no reason to use it, as I was already using the IDLE interactive shell to test syntax and so forth as coding. I didn't think the ability to auto-load packages or to surf the directory structure while coding was worth it. What a fool I was!

I've really gotten to love ipython and while I don't use the auto-load feature, I love the ability to easily move around and do what I need to do.
Do you use IPython for general python development, or is it all snippits of plotting equations and other scientific computing stuff? I just heard about Ipython from the thread was looking for some video tutorials or examples that could show what its capabilities are, but they all seem to be focused very tightly on scientific computing(using packages like linpack that I couldn't even find on Ubuntu) while I'm more interested in broader usage.

JetsGuy posted:

My only real beef is that it's a pain in the rear end to reload a package when you find a bug. I wish there was a simple reset command that would completely erase all previously loaded poo poo... in a reliable way.
This might be a dumb question since I don't know anything about ipython at this point, but is there a reason reload doesn't work?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

peepsalot posted:

This might be a dumb question since I don't know anything about ipython at this point, but is there a reason reload doesn't work?

The builtin reload function is useless.

etcetera08
Sep 11, 2008

Suspicious Dish posted:

The builtin reload function is useless.

Yeah, from what I have seen it's less of an IPython problem and more of a Python problem. There's no easy way to do it in Python either. Even if you soft restart IDLE (at least in 2.7) you get carry-over poo poo a lot of times.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

Suspicious Dish posted:

The builtin reload function is useless.
Care to elaborate on why exactly? I've used it in a few cases and it seemed to work as expected.

Scaevolus
Apr 16, 2007

peepsalot posted:

Care to elaborate on why exactly? I've used it in a few cases and it seemed to work as expected.
It doesn't work recursively.

If you call reload(a), and a imports b, it will use the cached b module. This is useless when you're working on b.

Scaevolus fucked around with this message at 03:39 on Apr 20, 2012

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Scaevolus posted:

It doesn't work recursively.

If you call reload(a), and a imports b, it will use the cached b module. This is useless when you're working on b.

I can see the ramifications in a lager program, but in your example if you are working on b why would you reload a instead?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

peepsalot posted:

Care to elaborate on why exactly? I've used it in a few cases and it seemed to work as expected.

If I create an instance of a.FooBar, or if I do from a import FooBar, or FooBar = a.FooBar, those objects aren't updated. In fact, we have both the old and new modules around. Unexpected behavior will occur.

The Gripper
Sep 14, 2004
i am winner

Suspicious Dish posted:

If I create an instance of a.FooBar, or if I do from a import FooBar, or FooBar = a.FooBar, those objects aren't updated. In fact, we have both the old and new modules around. Unexpected behavior will occur.
Yeah it's better used in applications where reloading modules is a desired behavior in production i.e. if you are using modules as plug-ins. At least that way you can handle pre-reload and post-reload operations and not end up with any artifacts.

Using it in development is trickier because of what you said, reloading a module because you made a change/fix (that you wouldn't do in production) means you either need to add extra code just for development, or skip it and just restart the entire application.

deimos
Nov 30, 2006

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

spengler posted:

I'm struggling with something pretty basic. I have an XML file that looks like this:

Kinda late for this, but if you don't care about adding a dependency I love the speed of lxml, and then there's this:
http://lxml.de/FAQ.html#how-can-i-map-an-xml-tree-into-a-dict-of-dicts


how!! posted:

So I wrote a python package, and I uploaded it to pypi. It installs fine via python setup.py install, but won't install via pip install [package_name]. What am I missing? The package is here: http://pypi.python.org/pypi/django-easydump

According to: http://priestc.github.com/django-easydump/ (which I got from your link) you have to: pip install django-easydump





As a side question, anyone know a good review on math subjects like linear algebra and diff eq?

I was looking at that markov chains pdf posted earlier and realized how much I had forgotten.

deimos fucked around with this message at 16:51 on Apr 20, 2012

vikingstrike
Sep 23, 2007

whats happening, captain

deimos posted:

Kinda late for this, but if you don't care about adding a dependency I love the speed of lxml, and then there's this:
http://lxml.de/FAQ.html#how-can-i-map-an-xml-tree-into-a-dict-of-dicts


According to: http://priestc.github.com/django-easydump/ (which I got from your link) you have to: pip install django-easydump





As a side question, anyone know a good review on math subjects like linear algebra and diff eq?

I was looking at that markov chains pdf posted earlier and realized how much I had forgotten.

Khan Academy has some pretty good, short math/stats tutorial videos.
http://www.khanacademy.org/#linear-algebra
http://www.khanacademy.org/#differential-equations
http://www.khanacademy.org/#probability

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

peepsalot posted:

Do you use IPython for general python development, or is it all snippits of plotting equations and other scientific computing stuff? I just heard about Ipython from the thread was looking for some video tutorials or examples that could show what its capabilities are, but they all seem to be focused very tightly on scientific computing(using packages like linpack that I couldn't even find on Ubuntu) while I'm more interested in broader usage.

I generally like using interactive shells in general to do make sure the code I'm writing is behaving the way I think it is. For example, if I wanted to write a loop on some 2D array, I might use the interactive shell to do a much smaller version just to see if it is working the way I expect. It helps me catch a lot of stupid mistakes before they happen.

All I do is scientific computing, so I don't know if you'd call that "python development" or not. I write programs to do my data analysis, which is usually huge data sets that a person couldn't do by hand. I have never, not once, wrote a GUI, although I have had to write some UI stuff so other people can use my code. Of course, it assumes that the only people that will ever see it are other scientists doing that task.

I have had to deal with other people's code entirely too much to not comment my code to a sickening level. I know people will say too much commenting is lovely coding, but whatever.

Anyway, ipython is nice because it still takes the regular shell commands from the python environment, and that alone is a dream.

Suspicious Dish posted:

If I create an instance of a.FooBar, or if I do from a import FooBar, or FooBar = a.FooBar, those objects aren't updated. In fact, we have both the old and new modules around. Unexpected behavior will occur.

This is pretty much the biggest issue I run into. I'll have some variable definied like:

x = a.foobar

but if I reload a, x isn't updated with the new a. I understand why, it's just frustrating.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

JetsGuy posted:

All I do is scientific computing,

Since I'm a huge science nerd...what do you do, if you can say?

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

Thermopyle posted:

Since I'm a huge science nerd...what do you do, if you can say?

Gamma-Ray Astrophysics.

Catalyst-proof
May 11, 2011

better waste some time with you
This is too cool not to share. Ever wanted the opposite of zip?

code:
In [1]: a = [1, 2, 3, 4]

In [2]: b = ['a', 'b', 'c', 'd']

In [3]: c = zip(a, b)

In [4]: c
Out[4]: [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')]

In [5]: d, e = zip(*c)

In [6]: d
Out[6]: (1, 2, 3, 4)

In [7]: e
Out[7]: ('a', 'b', 'c', 'd')

Zizzyx
Sep 18, 2007

INTERGALACTIC CAN CHAMPION

took me a second to figure out how it does that. thanks for sharing :)

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
You can think almost zip as a matrix transform, as well:

code:
L1 = [( 1 ,  2 ,  3 ),
      ('a', 'b', 'c')]

L2 = zip(*L1)

L2 = [( 1, 'a' ),
      ( 2, 'b' ),
      ( 3, 'c' )]
That is, we've swapped X and Y. Obviously, this is directly invertible.

devilmouse
Mar 26, 2004

It's just like real life.

Scaevolus posted:

It doesn't work recursively.

If you call reload(a), and a imports b, it will use the cached b module. This is useless when you're working on b.

If you're using ipython, you can sometimes use dreload() to do a recursive reload, depending on the project. You can also cheat and use %run to execute a program or module and it should be as if you were running it for the very first time.

edit: Test these first in your project to make sure it's not one of those unfortunate situations where it flakes out as sometimes happens.

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

Fren posted:

This is too cool not to share. Ever wanted the opposite of zip?

code:
In [1]: a = [1, 2, 3, 4]

In [2]: b = ['a', 'b', 'c', 'd']

In [3]: c = zip(a, b)

In [4]: c
Out[4]: [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')]

In [5]: d, e = zip(*c)

In [6]: d
Out[6]: (1, 2, 3, 4)

In [7]: e
Out[7]: ('a', 'b', 'c', 'd')

...

Wait... how did I never know about this function. So many loops could have not been written!! :gonk:

tef
May 30, 2004

-> some l-system crap ->

JetsGuy posted:

...

Wait... how did I never know about this function. So many loops could have not been written!! :gonk:

munctional programming!

code:

>>> fjords
[1, 18, 17, 15, 10, 14, 0, 6, 8, 19, 9, 5, 13, 2, 16, 4, 12, 11, 7, 3]
>>> for a,b in zip(fjords, fjords[1:]):
...     print a,b
... 
1 18
18 17
17 15
15 10
10 14
14 0
0 6
6 8
8 19
19 9
9 5
5 13
13 2
2 16
16 4
4 12
12 11
11 7
7 3
>>> 

Adbot
ADBOT LOVES YOU

etcetera08
Sep 11, 2008

tef posted:

munctional programming!

code:

>>> fjords
[1, 18, 17, 15, 10, 14, 0, 6, 8, 19, 9, 5, 13, 2, 16, 4, 12, 11, 7, 3]
>>> for a,b in zip(fjords, fjords[1:]):
...     print a,b
... 
1 18
18 17
17 15
15 10
10 14
14 0
0 6
6 8
8 19
19 9
9 5
5 13
13 2
2 16
16 4
4 12
12 11
11 7
7 3
>>> 

:aaaaa:

for other things along these lines check out @raymondh on twitter. He's a Python dev and tweets interesting little bits. Mostly Python 3 lately though.

  • Locked thread