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
Solaron
Sep 6, 2007

Whatever the reason you're on Mars, I'm glad you're there, and I wish I was with you.
So I'm messing around (my second day with Python, please forgive any horrible screwups thus far). The program works but I can't get the console window to stay open.

It's just a lunch picker for us guys at the IT desk to replace the little box we pull from.

code:
import random
import os

print('Choose your Lunch Destiny (tm):')
print('1: Deliver or 2: Carryout or 3: DANGER')
i = int(input('Make your choice:  '))

deliverList =['Pizza Hut', 'Rong Tan', 'La Rosas', 'Quiznos']
carryList =['Burger King', 'Skyline Chili', 'Sonic', 'Big Boy', 'BW3', 'Buffalo Wings and Rings', 'Great Steak', 'Subway', 'McDees'] 

if i == 1:
    print(random.choice(deliverList))
elif i == 2:
    print(random.choice(carryList))
else:
    print("You get White Castle!")


os.system("pause")
My issue is that after the program runs it closes. I read that the last line should resolve that, but maybe I did it wrong, or maybe it doesn't in 3.0. Any help? I know this actually isn't anything important or hard at all, just annoying me. I did Google it and tried the few ideas there.

Adbot
ADBOT LOVES YOU

Id4ever
Dec 2, 2004

Solaron posted:

My issue is that after the program runs it closes. I read that the last line should resolve that, but maybe I did it wrong, or maybe it doesn't in 3.0. Any help? I know this actually isn't anything important or hard at all, just annoying me. I did Google it and tried the few ideas there.

I'm assuming this is on Windows, and that the problem is that the console window closes automatically. One workaround is to replace the last line with:
code:
raw_input()
With this change the program will close once you press enter.

Edit: Though, your original code works fine on my system. It's possible pause.exe isn't part of a standard Windows installation, I probably got it from cygwin/mingw.

Id4ever fucked around with this message at 18:41 on Apr 2, 2009

Solaron
Sep 6, 2007

Whatever the reason you're on Mars, I'm glad you're there, and I wish I was with you.
Hm... I'm using Python 3.0, and I guess raw_input has been changed to just input. My window still closes... bugs the hell out of me. Let me try a different PC.

Ethereal
Mar 8, 2003
Looks like I fixed my issue...though I don't remember how. Thanks anyway!

Insidious
Dec 17, 2004


GODDAMNIT APHEX WHY DO YOU SUCK AT EVERYTHING YOU DO
Anybody have any experience with regex positive lookahead in python?

I'm trying to reproduce what is being done here:
http://www.bennadel.com/blog/1105-Ask-Ben-Breaking-An-SMS-Text-Message-Up-Into-Multiple-Parts.htm

In a nutshell, splitting up a long line into 450 character maximum lines, while also taking care not to split up lines in the middle of words.
If the 450 char limit is encountered in the middle of a word, the regex will backtrack to the start of the word and end the match there.

This works fine in my regex tester program:



But the regex mysteriously fucks up in actual python code. Here's a code fragment.
code:
message = "\"The budget for the Solar Energy Research Institute - which President Jimmy Carter had created to spearhead solar innovation - was slashed under Reagan from $124 million in 1980 to $59 million in 1982:. Scientists who had left tenured university jobs to work on the project were given two weeks notice and no severance pay. The squelching of the institute - later partly re-funded and renamed the National Renewable Energy Laboratory - marked the start of Reagan's campaign against solar power. By the end of 1985, when Congress and the administration allowed tax credits for solar homes to lapse, the dream of a solar era had faded. The solar water heater President Carter had installed on the White House roof in 1979 was dismantled and junked. Solar water heating went from a billion-dollar industry to peanuts overnight; thousands of sun-minded businesses went bankrupt.\" --Arthur Allen"


chunks = re.findall(r".{1,450}(?=([\s\-:]|$))", message)
print chunks
Output:
code:
[' ', ' ', '\n']
What is going wrong????? :froggonk:

Insidious fucked around with this message at 09:30 on Apr 3, 2009

dorkanoid
Dec 21, 2004

The first part is not "selected", you're effectively only finding the "latest whitespace before 450 chars"

code:
(.{1,450})(?:[\s\-\:]|$)
works for me in http://cthedot.de/retest/

EDIT:
code:
(.{1,450})(?=(?:[\s\-\:]|$))
is probably closer to what you want; the other one consumes the whitespace character

dorkanoid fucked around with this message at 09:48 on Apr 3, 2009

tef
May 30, 2004

-> some l-system crap ->
The pycon videos are up:

http://pycon.blip.tv/file/1947354/

king_kilr
May 25, 2007

tef posted:

The pycon videos are up:

http://pycon.blip.tv/file/1947354/

You picked a great one to link :)

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

king_kilr posted:

You picked a great one to link :)

I thought so too :)

hey mom its 420
May 12, 2007

Awesome talk!

king_kilr
May 25, 2007

m0nk3yz posted:

I thought so too :)

Well, in that case, allow me to pimp myself out: http://pycon.blip.tv/file/1949388/ :)

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

king_kilr posted:

Well, in that case, allow me to pimp myself out: http://pycon.blip.tv/file/1949388/ :)

Hay I was at that one. :)

deimos
Nov 30, 2006

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

m0nk3yz posted:

Hay I was at that one. :)

Were you the one yelling "can't hear you" at the beginning?

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

deimos posted:

Were you the one yelling "can't hear you" at the beginning?

Negative. I tend not to yell

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
Does anyone know of a good archive for PyCon 2008 videos? There is a particular presentation I would like to watch (the Pygame one) but cannot find it.

Additionally, I am starting a small Pygame project (~3 month project w/ a team of 5) and if anyone has any words of wisdom regarding Pygame or Python game development in general I would love to hear it.


edit: I am particularly interested about Python 2.5.4 vs Python 2.6 with Pygame. The Pygame website suggests that Python 2.5.4 is the "best" python on windows - but that seems like a pretty weak argument and it would be nice to use 2.6. However, if that means it could lead into trouble with Pygame down the road, then I am fine sticking with 2.5.

supster fucked around with this message at 08:47 on Apr 4, 2009

Scaevolus
Apr 16, 2007

supster posted:

Does anyone know of a good archive for PyCon 2008 videos? There is a particular presentation I would like to watch (the Pygame one) but cannot find it.

Additionally, I am starting a small Pygame project (~3 month project w/ a team of 5) and if anyone has any words of wisdom regarding Pygame or Python game development in general I would love to hear it.


edit: I am particularly interested about Python 2.5.4 vs Python 2.6 with Pygame. The Pygame website suggests that Python 2.5.4 is the "best" python on windows - but that seems like a pretty weak argument and it would be nice to use 2.6. However, if that means it could lead into trouble with Pygame down the road, then I am fine sticking with 2.5.
Is it this http://www.youtube.com/watch?v=EGSgLuxrgYc ?

Before you embark on a major PyGame project, you should tale a look at pyglet. It renders with OpenGL, which is much faster than the software rendering PyGame does. If you know OpenGL, you can use it to make the graphics a lot fancier as well.

Pyglet Programming Guide

Sylink
Apr 17, 2004

I saw in TV IV during the BSG finale some bingo app that was a py file running in a browser. How is this done?

Beyond that what are good resources for python in web apps and can you actually run python through a browser like javascript or something?

king_kilr
May 25, 2007

Sylink posted:

I saw in TV IV during the BSG finale some bingo app that was a py file running in a browser. How is this done?

Beyond that what are good resources for python in web apps and can you actually run python through a browser like javascript or something?

There's no direct way to run Python in the browser, but PyPy can translate Python into javascript(which can be run in the browser), and IronPython can be used to run Python through silverlight, and probably something with Jython and Java applets, though I'm not sure about that.

bitprophet
Jul 22, 2004
Taco Defender

king_kilr posted:

There's no direct way to run Python in the browser, but PyPy can translate Python into javascript(which can be run in the browser), and IronPython can be used to run Python through silverlight, and probably something with Jython and Java applets, though I'm not sure about that.

Perhaps he saw someone using PSP or some other Python-via-Apache method that was configured to leave the .py on the end of the URL?

king_kilr
May 25, 2007

bitprophet posted:

Perhaps he saw someone using PSP or some other Python-via-Apache method that was configured to leave the .py on the end of the URL?

Could be, most python deployment methods let you control the URLs anyway you want, so really you could set yourself up to have the URL end with just about anything(yes this is technically possible with any language using mod_rewrite).

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH

Scaevolus posted:

Is it this http://www.youtube.com/watch?v=EGSgLuxrgYc ?

Before you embark on a major PyGame project, you should tale a look at pyglet. It renders with OpenGL, which is much faster than the software rendering PyGame does. If you know OpenGL, you can use it to make the graphics a lot fancier as well.

Pyglet Programming Guide
No, it's another one titled "Pygame: Modern game development".

I had considered Pyglet before and decided to stick with Pygame, but now you have me torn. One of the programmers knows OpenGL (not me) and the other does not (me). Is performance really that much of an issue in Pygame? We will be making some prototypes over the next few weeks, maybe we will use Pyglet for some and see how it compares.

Sylink
Apr 17, 2004

That was probably it, I was just impressed by it.

Other than that, can anyone recommend a python module(s) for drawing graphics?

I might want to make my own plotting module or something but I'd like something that can create graphics of any type.

Am I stuck just using the tkinter canvas widget?

I don't want to animate really either.

Scaevolus
Apr 16, 2007

supster posted:

I had considered Pyglet before and decided to stick with Pygame, but now you have me torn. One of the programmers knows OpenGL (not me) and the other does not (me). Is performance really that much of an issue in Pygame? We will be making some prototypes over the next few weeks, maybe we will use Pyglet for some and see how it compares.
If your game is going to have lots of sprites, you might run into issues with performance in PyGame. You can use pyglet without knowing OpenGL-- it wraps it completely, and you only need to use the calls if you want to.

Look through the Astraea (an Asteroids clone) game that's included in the pyglet examples.

It only directly calls openGL in 15 lines, to:
  • Color the menu pointer (could also be done by setting the color attribute of a sprite)
  • Draw the starfield so that it wraps
  • Draw the borders
  • Set the alpha blending mode

None of these are really necessary, and the guy who knows OpenGL could do them easily.

High ceilings are nice.

Scaevolus fucked around with this message at 23:34 on Apr 4, 2009

tripwire
Nov 19, 2004

        ghost flow

Sylink posted:

That was probably it, I was just impressed by it.

Other than that, can anyone recommend a python module(s) for drawing graphics?

I might want to make my own plotting module or something but I'd like something that can create graphics of any type.

Am I stuck just using the tkinter canvas widget?

I don't want to animate really either.

PyCairo works well enough, depends on what you are drawing exactly. http://cairographics.org/pycairo/

ukrainius maximus
Mar 3, 2007
So I'm pretty hosed for this one assignment I have for my Artificial Intelligence class. Ya see, I needed to fill up my schedule and this AI course was the only one that would work for me, so despite the fact that its a high level class and I'm new to my major (Computer Science, I barely have experience with C++) I am now in a predicament. I have this lovely assignment to write these two Python scripts for this MobileSim poo poo to try and make this little robot thing do some poo poo and I honestly have no clue where to even begin :(

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

ukrainius maximus posted:

So I'm pretty hosed for this one assignment I have for my Artificial Intelligence class. Ya see, I needed to fill up my schedule and this AI course was the only one that would work for me, so despite the fact that its a high level class and I'm new to my major (Computer Science, I barely have experience with C++) I am now in a predicament. I have this lovely assignment to write these two Python scripts for this MobileSim poo poo to try and make this little robot thing do some poo poo and I honestly have no clue where to even begin :(

Is there another major or some poo poo you could switch to?

Sorry, I mean http://www.gethomeworkhelp.com/Computer_Science_61.php.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
I hope this helps or whatever:
code:
if robot or some_shit:
    do_some_shit()

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

Lonely Wolf posted:

I hope this helps or whatever:
code:
if robot or some_shit:
    do_some_shit()

Bah:
code:
shit_done = [ do_shit(poo poo) for poo poo in some_shit if robot != some_other_shit ]
Or:
code:
import robots
import some_shit

some_shit.do(robots(count=10))

king_kilr
May 25, 2007

m0nk3yz posted:

Bah:
code:
shit_done = [ do_shit(poo poo) for poo poo in some_shit if robot != some_other_shit ]
Or:
code:
import robots
import some_shit

some_shit.do(robots(count=10))

Hah, I assume your account has been hacked, because the real monk3yz would parallelize that to kingdom come.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
He's clearly simplified it, for pedagogic reasons.

ukrainius maximus
Mar 3, 2007
haha thanks for the help :)

on a more serious note though, have any of you used this poo poo called MobileSim before? this is what's dicking my balls right now and I sort of want to kill something that's alive

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
Can anyone explain to me what's going here? I found another solution to the problem I was trying to solve, but I would still like to better understand how Python inheritance and super() works.

My goal here is to override the .x attribute of Parent in Child with a property.

http://pastie.org/438066

The error message leads me to believe that super(Child, self) is not returning an instance of the Parent class (or a proxy for the Parent class or whatever) as I am expecting it to.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

m0nk3yz posted:

code:
shit_done = [ do_shit(poo poo) for poo poo in some_shit if robot != some_other_shit ]
code:
import robots
import some_shit

some_shit.do(robots(count=10))

you should use stackless:

code:
import robots
import some_shit
import stackless

shit_done = [ stackless.tasklet(robots.do)(poo poo) for poo poo in some_shit.poo poo if robots != some_shit.other_shit ]

stackless.run()

m0nk3yz
Mar 13, 2002

Behold the power of cheese!

MeramJert posted:

you should use stackless:

code:
import robots
import some_shit
import stackless

shit_done = [ stackless.tasklet(robots.do)(poo poo) for poo poo in some_shit.poo poo if robots != some_shit.other_shit ]

stackless.run()

No I should write my own loving coroutine library and poo poo it all over the loving internet. That is the way of the world.

Benji the Blade
Jun 22, 2004
Plate of shrimp.

supster posted:

My goal here is to override the .x attribute of Parent in Child with a property.

http://pastie.org/438066

The error message leads me to believe that super(Child, self) is not returning an instance of the Parent class (or a proxy for the Parent class or whatever) as I am expecting it to.

There are a couple problems here.

First, when I run similar code to yours using 2.5, I get "TypeError: 'super' object has only read-only attributes (assign to .x)" in Child's x setter. I don't know a ton about objects of type super, but it appears you can't assign to one.

Second, you have a more basic misunderstanding when you write "super(Child, self).x = self._x + 1". This is supposing that there is Parent's x attribute hiding on your Child object behind its x property, but that's not the case. The x property overwrites the 'x' slot on that object. Notice that we can still access a parent's methods, but that's because we look them up from the parent class' namespace, not the self object's namespace.

So, even if your x setter worked, it would be recursive, and would terminate when you ran out of stack space.

Scaevolus
Apr 16, 2007

supster posted:

Can anyone explain to me what's going here? I found another solution to the problem I was trying to solve, but I would still like to better understand how Python inheritance and super() works.

My goal here is to override the .x attribute of Parent in Child with a property.

http://pastie.org/438066

The error message leads me to believe that super(Child, self) is not returning an instance of the Parent class (or a proxy for the Parent class or whatever) as I am expecting it to.
This problem was solved on IRC. What he was really wondering about was how to make rabbyt sprites not have artifacts when rendered at float coordinates. He was trying to make the coordinates autoround to ints, but the solution was to set the rendering mode to GL_NEAREST.

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:

Is it this http://www.youtube.com/watch?v=EGSgLuxrgYc ?

Before you embark on a major PyGame project, you should tale a look at pyglet. It renders with OpenGL, which is much faster than the software rendering PyGame does. If you know OpenGL, you can use it to make the graphics a lot fancier as well.

Pyglet Programming Guide

I'm almost certain that PyGame also uses hardware acceleration, because IIRC it's just a wrapper around SDL. I've used it for OpenGL-based stuff before.

Benji the Blade
Jun 22, 2004
Plate of shrimp.

Janin posted:

I'm almost certain that PyGame also uses hardware acceleration, because IIRC it's just a wrapper around SDL. I've used it for OpenGL-based stuff before.

Last I checked, while SDL has tools to provide an OpenGL context, it does not provide any sort of hardware-accelerated support for things such as drawing, rotating, or scaling sprites. For that, you'd have to write your own OpenGL calls.

Things like SDL_BlitSurface provide, IIRC, just your usual software blit.

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH

Scaevolus posted:

This problem was solved on IRC. What he was really wondering about was how to make rabbyt sprites not have artifacts when rendered at float coordinates. He was trying to make the coordinates autoround to ints, but the solution was to set the rendering mode to GL_NEAREST.
I actually posted this long after the problem was fixed - I just want to know what I am missing about inheritance in Python.


Benji the Blade posted:

There are a couple problems here.

First, when I run similar code to yours using 2.5, I get "TypeError: 'super' object has only read-only attributes (assign to .x)" in Child's x setter. I don't know a ton about objects of type super, but it appears you can't assign to one.

Second, you have a more basic misunderstanding when you write "super(Child, self).x = self._x + 1". This is supposing that there is Parent's x attribute hiding on your Child object behind its x property, but that's not the case. The x property overwrites the 'x' slot on that object. Notice that we can still access a parent's methods, but that's because we look them up from the parent class' namespace, not the self object's namespace.

So, even if your x setter worked, it would be recursive, and would terminate when you ran out of stack space.
This doesn't really make sense - you are implying that all functions in Python are virtual, but clearly it's working in the constructor. Is the __init__ function a special case and not virtual? If this is the case, is there specifically a different way I can access the base class's method that has been overriden?


edit:
If x was a method in the base class I think I could just call Parent.x(self, value) and be fine, but because it is an attribute I can't do that.

supster fucked around with this message at 20:23 on Apr 6, 2009

Adbot
ADBOT LOVES YOU

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
edit: double :(

  • Locked thread