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
Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.
Bluuuuuuggggggh. Trying to submit some stuff via webform automatically using Mechanize, except whoever made the site was a loving moron and gave a particular textarea two name and two ID tags. Hence, mechanize only ever saves the second one (which is the wrong one), but browsers pass through the first name (the right one).

Adbot
ADBOT LOVES YOU

M31
Jun 12, 2012

Pudgygiant posted:

Ok, this is the ugly rear end amateur hour script I have after switching to Yahoo finance. So much easier to pull down a csv than it is to scrape.

You might not care about this, but that Yahoo API is not public, and using it is against the ToS.

My Rhythmic Crotch
Jan 13, 2011

Has anyone used smtplib to send email to a Gmail account? I'm doing it the way described here and for some reason Gmail chooses to display the text version while my Outlook based email displays the HTML version.

However if I use code like this of course the HTML version is shown because there is no alternative.

Unfortunately, I've not been able to figure out what I need to do to make Gmail display the HTML version when using the two-part technique. Has anyone done this before?

Civil Twilight
Apr 2, 2011

My Rhythmic Crotch posted:

Unfortunately, I've not been able to figure out what I need to do to make Gmail display the HTML version when using the two-part technique. Has anyone done this before?

I haven't done it in a while, but I might be able to help. Tried the example code, and it works for me; can you use the 'show original' option in Gmail's dropdown menu and pastebin the email source so I can see exactly what's being sent?

My Rhythmic Crotch
Jan 13, 2011

Sure, here ya go: http://pastebin.com/VRrvAwgJ

Edit, my templates were hosed up there, here is an example where I've used the correct templates to generate the text and html versions. It produces the same behavior. http://pastebin.com/F0Y24ekf

My Rhythmic Crotch fucked around with this message at 14:29 on Nov 19, 2012

Civil Twilight
Apr 2, 2011

Switch the order of the parts.

# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.

(Also, you've got "</html>" where you mean "<body>", but gmail is ignoring that anyway)

The Gripper
Sep 14, 2004
i am winner
Yeah, the RFC says use the last alternative to display, and google follows it strictly.

A ton of mail clients just use the most-probably-wanted part based on MIME type which is mostly assumed to be HTML unless you've intentionally toggled HTML off, so people that don't actually know the RFC (most people) just assume it works that way by default and a lot of references/tutorials on creating and sending emails have that error.

My Rhythmic Crotch
Jan 13, 2011

Oh wow, well that was easy. Thank you both kindly :tipshat:

duck monster
Dec 15, 2004

Oh my loving god. Python/mysql on a mac.

I'm going to smash my god drat head in with a hammer.

APPLE INCLUDE THIS GODFORSAKEN loving MODULE IN YOUR PYTHON PLEASE?

4 hours of compilers crashing and poo poo breaking later, I just want to punch people in the head!

I'm running some code thats generating about half a million records from astronomical data, and sqlite3 just has its arse hanging out (When I run it through qcachegrind, its getting grotsequely bogged down at sqlite3 commit, so its time for a real database..... *record goes scratching off side of record*

Has someone, like, made a downloadable DMG that just installs this loving thing instead of forcing me to cycle through about 50 different long rear end tutorials on installing this poo poo , each of which doesnt work for different reasons to the previous one?

"ERROR: CLANG? Balls to that , fucker!"

"ERROR: You installed mysql with brew. INITIATING LAUNCH SEQUENCE"

"ERROR: You look like your about to succeed? LETS CRASH FOR NO REASON"

duck monster fucked around with this message at 15:58 on Nov 19, 2012

My Rhythmic Crotch
Jan 13, 2011

DMGs are available here: http://www.mysql.com/downloads/mysql/

I have yet to try it, but it's reported working even with Lion

duck monster
Dec 15, 2004

My Rhythmic Crotch posted:

DMGs are available here: http://www.mysql.com/downloads/mysql/

I have yet to try it, but it's reported working even with Lion

Yeah, I installed that, but I'm damned if I can get that version working with python at all.

I'm modifying setup_posix.py as I'm supposed to to;-

mysql_config.path = "/usr/local/mysql/bin/mysql_config"

But yeah;-

quote:

ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so
Reason: image not found

Basically: gently caress this poo poo.

Civil Twilight
Apr 2, 2011

Have you considered using MySQL's pure-python connector?

duck monster
Dec 15, 2004


I dont feel particularly inclined to attempt rewriting django. Even with the hack to try and fool django into using it as a drop in, its subtly incompatible enough not to be compatible at all.

My Rhythmic Crotch
Jan 13, 2011

Oh you're trying to host Django on a Mac? Yeah, I can feel your pain. I'm doing the same thing and I've stuck with sqlite and will continue to do so until I deploy onto Linux hosting.

duck monster
Dec 15, 2004

My Rhythmic Crotch posted:

Oh you're trying to host Django on a Mac? Yeah, I can feel your pain. I'm doing the same thing and I've stuck with sqlite and will continue to do so until I deploy onto Linux hosting.

Normally I use sqlite, but I have a loving massive dataset I'm working with and it just breaks sqlite.

e: Ah gently caress, and postgres is even slower :( Maybe I need to bite the bullet and parallelize this :/

e2: Scratch that. Significantly faster.

duck monster fucked around with this message at 19:02 on Nov 19, 2012

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

duck monster posted:

Normally I use sqlite, but I have a loving massive dataset I'm working with and it just breaks sqlite.

e: Ah gently caress, and postgres is even slower :( Maybe I need to bite the bullet and parallelize this :/

e2: Scratch that. Significantly faster.

I was about to suggest you try and use postgres instead

geera
May 20, 2003
Does anyone with Flask experience know whether it's possible to add sub-folders to the /static/ folder for organization? I created /static/css/test.css and Flask's dev server returns a 404 when I try to access it. Any file at the top level of /static/ works fine though.

From the reading I've done, static assets should be served by nginx or Apache or whatever in production (rightly so), but it would make life a whole lot easier during development if the dev server supported that also.

Civil Twilight
Apr 2, 2011

geera posted:

Does anyone with Flask experience know whether it's possible to add sub-folders to the /static/ folder for organization?

It is. It's a little paranoid about URLs for security reasons, though, so you might want to check the precise paths you're using: http://127.0.0.1:5000/static/blah/test.txt will work, while http://127.0.0.1:5000/static//blah/test.txt will return 404.

stubblyhead
Sep 13, 2007

That is treason, Johnny!

Fun Shoe
I'm in the process of learning python, and I'm having trouble with array slice syntax. So foo[1:4] will return indices 1-3, which is really counter-intuitive to me. What's the reasoning for the second number being the first index not included instead of the last index that is? The latter seems more logical to me, but I'm sure there are things I haven't taken into consideration about why that would be a bad idea.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

stubblyhead posted:

I'm in the process of learning python, and I'm having trouble with array slice syntax. So foo[1:4] will return indices 1-3, which is really counter-intuitive to me. What's the reasoning for the second number being the first index not included instead of the last index that is? The latter seems more logical to me, but I'm sure there are things I haven't taken into consideration about why that would be a bad idea.
For consistency, it uses the same start and end values as the range() function. The single-argument form of range(n), according to the docs, generates a list of exactly n values.

This is one of those things that constantly frustrates the poo poo out of people who regularly switch between Ruby and Python for different projects.

Suspicious Dish
Sep 24, 2011

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

stubblyhead posted:

I'm in the process of learning python, and I'm having trouble with array slice syntax. So foo[1:4] will return indices 1-3, which is really counter-intuitive to me. What's the reasoning for the second number being the first index not included instead of the last index that is? The latter seems more logical to me, but I'm sure there are things I haven't taken into consideration about why that would be a bad idea.

The length of the set returned is the difference between the two numbers, to make math easier, and for other reasons. So that means we either exclude the first number, or the last number. At this point, it's more nitpicky, but the common reasoning is that getting the first three elements should be foo[0:3], not foo[-1:2].

Civil Twilight
Apr 2, 2011

Misogynist posted:

This is one of those things that constantly frustrates the poo poo out of people who regularly switch between Ruby and Python for different projects.

It really, really does. The difference between Python and Ruby list slicing syntax is the single most annoying thing about using both languages for me.

Opinion Haver
Apr 9, 2007

It means that foo[0:3] + foo[3:8] = foo[0:8].

Sylink
Apr 17, 2004

So I'm using pyglet and I want to draw a bar graph based on some arbitrary data.


Is the best approach to this to try and learn a bunch of opengl and draw primitives or would it matter if I hacked it together using sprites?

The pyglet docs seem to assume you already know opengl so making simple lines and such are not the easiest thing, not to mention they seem to suffer somehow since even a simple square flickers like mad compared to say, the primitives in pygame.

EDIT: Or if someone can point me to a good tutorial on basic opengl stuff that would help too, I'm mostly looking to stay in 2D land so I don't how much it matters.

Sylink fucked around with this message at 15:25 on Nov 20, 2012

Emacs Headroom
Aug 2, 2003

Civil Twilight posted:

It really, really does. The difference between Python and Ruby list slicing syntax is the single most annoying thing about using both languages for me.

Oh weird, Ruby is inclusive. I guess it's at least a nice mnemonic that they use a[i..j] syntax instead of a[i:j], so it's kind of like Bash both in syntax and semantics.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

Sylink posted:

So I'm using pyglet and I want to draw a bar graph based on some arbitrary data.

Is there a good reason why you're trying to use a sledgehammer to pound in a screw? Why not use matplotlib?

OnceIWasAnOstrich
Jul 22, 2006

Lysidas posted:

Is there a good reason why you're trying to use a sledgehammer to pound in a screw? Why not use matplotlib?

Or if you are attached to the idea of plotting with OpenGL for whatever reason (maybe interactivity or something) you could use something like Visvis, Veusz or Chaco (not actually all OpenGL, some of them are Qt or something) which can do much prettier and more interactive plots than matplotlib. I actually can't stand matplotlib and would rather use the R plotting functions through Rpy2 than use it, I just had a bunch of bad experiences trying to make it work.

Sylink
Apr 17, 2004

I want interactivity and responsiveness.

There are plenty of Python libraries that will generate really nice graphic images but I want something running off live data.

And I got some opengl stuff working but the way pyglet makes you do it is very weird and if you call it directly its harder to use the buffers to draw tons of primitives at once. It can probably be done anyway but the documentation is so poor I can't tell.

Spime Wrangler
Feb 23, 2003

Because we can.

I found chaco to be a little weird at first but way more powerful than matplotlib in the end. Great for live data.

I actually started a project a while back using chaco to draw networkx graphs and ended up installing the whole enthought distribution (which chaco is a part of) and making everything with enable and canvas. Enable has a PDF vector drawing system which when paired with its canvas module lets you easily make draggable, zoomable, arbitrarily large interactive 2D spaces.

The only downside is that the documentation is a bit lacking so plan to spend a bunch of time poking around their examples and source code. I had exactly zero GUI experience and once I figured the system out it became ridiculously easy to work with.

Captain Capacitor
Jan 21, 2008

The code you say?
I have found NodeBox and Python to produce some really nice-looking visuals. Go to the "Twitter is the new shampoo" on this page

Spime Wrangler
Feb 23, 2003

Because we can.

Son of a bitch. That looks good.

Dren
Jan 5, 2001

Pillbug

duck monster posted:

Normally I use sqlite, but I have a loving massive dataset I'm working with and it just breaks sqlite.

e: Ah gently caress, and postgres is even slower :( Maybe I need to bite the bullet and parallelize this :/

e2: Scratch that. Significantly faster.

If you are willing to go non-relational mongo has a really nice python library.

duck monster
Dec 15, 2004

Dren posted:

If you are willing to go non-relational mongo has a really nice python library.

NoSQL is cargo-cult technology. Postgres is working fine

Salsa McManus
Jul 12, 2007

Khezu Khezu Khezu Khezu Khezu Khezu Khezu Khezu
I've exhausted my extremely limited Python knowledge attempting to troubleshoot this thing, so I'll bring it before the masters. When I run the game I get a 'global name "colormatch" is not defined' error in the handle_collide function in the Balloons class. If anyone could identify what the issue is I'd love it.

I didn't want to fill up an entire page with code, so I pasted it to a pastebin. http://pastebin.com/G6JyRZ48

The Gripper
Sep 14, 2004
i am winner
It's just because you're not actually declaring colormatch before you're using it, as global variable just tells the interpreter that the variable is global without actually creating it.

You shouldn't need to mark anything as global in your Balloons class either (unless you're creating the variable in that class), once the interpreter knows a variable is global it's usable everywhere:
Python code:
class Test1:
    def __init__(self):
        print my_global_var


class Test2:
    def __init__(self):
        global my_global_var
        print my_global_var


def main():
    global my_global_var
    my_global_var = "some data"
    x = Test1()
    y = Test2()

if __name__ == "__main__":
    main()
Both Test1 and Test2 classes have access to my_global_var.


vvv and like Jewel said, globals aren't really used that often as it's easier and less error-prone to just pass the variables directly into your class, and create classes to hold methods that require shared data. In your code, most of your methods like display_balloons, load_image etc. would be better placed in a MyGame class that keeps track of everything, and your globals in Balloons should actually be part of the Balloons class.

The Gripper fucked around with this message at 07:27 on Nov 23, 2012

Jewel
May 2, 2009

I just woke up so I'm not in a state to actually fix your code, but I'm wary about your use of globals regardless. I don't think I've ever needed globals in python, because it's just so easy to pass things through the code?

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Jewel posted:

I just woke up so I'm not in a state to actually fix your code, but I'm wary about your use of globals regardless. I don't think I've ever needed globals in python, because it's just so easy to pass things through the code?

I'm doing Cousera's Interactive Introduction to Interactive Programming in Python and it's really weirding me out by how much they use globals there. http://www.codeskulptor.org/#examples-blackjack_template.py :confused:

Salsa McManus
Jul 12, 2007

Khezu Khezu Khezu Khezu Khezu Khezu Khezu Khezu
I didn't expect a reply so fast! After reading your posts I managed to fix it.

Honestly, this is actually for an Intro to Game Design class so I was following a set of instructions that weren't too well written. Starting to question the validity of this class as time goes on judging from the PDF tutorials we are given.

Edit - I'm dumb. I forgot the balloons are supposed to go up a line when they're unblocked.

Salsa McManus fucked around with this message at 22:50 on Nov 23, 2012

Nippashish
Nov 2, 2005

Let me see you dance!

Symbolic Butt posted:

I'm doing Cousera's Interactive Introduction to Interactive Programming in Python and it's really weirding me out by how much they use globals there. http://www.codeskulptor.org/#examples-blackjack_template.py :confused:

Most of the things at the top are static data, which is fine as globals because it's not going to change. Also, people will hate on you for globals, but sometimes (like when you're writing an isolated 100 line script) it's not a big deal.

The stuff at the bottom I suppose should be inside an if __name__ == "__main__": block, but I can understand why they left that out in an introduction because honestly that is a seriously weird convention.

Adbot
ADBOT LOVES YOU

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
Is there a thin database abstraction layer for Python that basically just takes user-supplied connection strings using whatever database driver a user feels like without having to do a bunch of manual legwork to import and instantiate some arbitrary class name in my own code? I don't want an ORM.

  • Locked thread