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

Being pretty inexperienced I often have a hard time judging the quality/reliability/pitfalls of modules that don't have a lot of online ink written about them.

So.... I ask, has anyone here used y_serial?

On the surface, it seems like a pretty cool module for data persistence. I have a soft spot for useful modules that use nothing but standard library and are pure python. Thoughts?

(As a side note it's some of the most usefully documented code I've ever read...very educational to an amateur like me)

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

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

Yakattak posted:

I'm looking for a module that allows me to connect to a MySQL database. I've tried pymysql but it's bugged, so you can't SELECT more than one row (which sucks). Anyone have any good modules they wish to share?

The standard answer is mysqldb. I've been needing something in pure python, so I've been using MySQL Connector/Python.

Thermopyle
Jul 1, 2003

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

Yakattak posted:

:psyduck:

When I do setup.py install, it keeps saying:
code:
error: package directory 'mysql' does not exist
And it's clearly in there, anyone else encounter this problem with the latest rev?

I don't know the answer in any case, but you should probably specify which of the two packages I mentioned you're trying.

Thermopyle
Jul 1, 2003

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

Habnabit posted:

oursql is pretty much the best thing that's out there right now. The top of that link has a whole list of reasons why you should use it over mysqldb.

myconnpy is a bit of a mess. I've been considering rewriting it from scratch with support for twisted.

I take it your a (the?) dev of oursql?

Is it pure python?

Thermopyle
Jul 1, 2003

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

Habnabit posted:

The only dev. It's written almost entirely in cython, with a bit of C and some code generation stuff in python.

Too bad. That makes it not usable with things like greenlet or eventlet. :(


king_kilr posted:

I've never heard of ANYONE using MySQL Connector/Python.

HTH.

Then you're not reading this thread since I mention using it several posts up. :D

Thermopyle
Jul 1, 2003

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

This is a "point me in the right direction" question...

I'd love to be able to analyze a video file and determine to some decent degree of accuracy if it contains a station logo (like if it says NBC or SyFy). I don't really care about what logo it is, just if it has a logo at all.

I realize this is a fuzzy and ongoing area of research, but I'd at least like to experiment with it. Any libraries for this sort of thing? Any articles you can recommend? Any sort of pointers at all?

Thermopyle
Jul 1, 2003

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

I hate web design with a passion.

What's the best library or framework for abstracting away as much of it as possible?

Something useful for getting input from a user via forms or whatever web magic is possible and displaying results to them.

I'm not horribly concerned with making it beautiful, just functional.

Thermopyle
Jul 1, 2003

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

Stabby McDamage posted:

If you don't want to touch HTML, I think you'd want something higher level. I'm not sure what that is, but I'd be very surprised if there wasn't some framework for making CRUD apps without HTML.

This is more along the lines of what I'm looking for.

In my ideal world, I'm looking for "print" and "raw_input" for the web.

bitprophet posted:

That says to me he's doing the usual conflation of "web design" with "web development" and doesn't actually mean the visual design aspect of things.

So he probably does want Django :shobon:

Regarding the HTML/CSS crap one does have to deal with either way, something like Blueprint CSS can help make a simple site look significantly better than CSS-less HTML will, with almost no work necessary. Certainly from a typography and layout perspective.

I don't want to do web development or design.

If that's not possible, then I'm looking for the thing that gets me the closest.

Thermopyle
Jul 1, 2003

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

This is the sort of thing that I always do in 15 lines and someone shows me how to do in 2...

Say I have a list of strings that are sorted the way I want them and that this isn't alphabetical...completely arbitrary sort order. Now I'm building another list of strings and I want to use the first list as the specification to sort the second list.

Bonus points for sorting strings in the second list that aren't in the first list to the end.

code:
master_string = ['this is a string', 'what up', 'dicks', 'bar', 'foo']
unsorted_string = ['dicks', 'what up', 'this is a string', 'foo', 'bar']

bonus = ['dicks', 'what up', 'word to your mother', 'this is a string', 'foo', 'bar', 'emo cutter']
code:
>>> magical_sort(unsorted_string, master_string)
['dicks', 'what up', 'this is a string', 'foo', 'bar']

>>> magical_sort(bonus, master_string)
['dicks', 'what up', 'this is a string', 'foo', 'bar', 'word to your mother', 'emo cutter']

Thermopyle
Jul 1, 2003

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

Fayk posted:

I think I'd be more comfortable if I understood the metaphors and methods used - like some commands don't work - it seems all special-cased, but I can't see how and where. I should look at it more, though...

Yeah, this is why I installed ipython and then only used it once or twice.

Thermopyle
Jul 1, 2003

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

How the heck do you use virtualenv with ipython?

Thermopyle
Jul 1, 2003

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

Shaocaholica posted:

How do I use non scrolling output? For instance, if I want to draw a progress bar in the terminal? Is there something I should be using other than print and sys.stdout.write()?

I typically do something like:

code:
for i in range(10):
    print str(i) + "\r",
The \r returns to the line beginning and the comma at the end suppresses the newline.

Thermopyle
Jul 1, 2003

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

Shaocaholica posted:

Ok, I got that working and it seems to do what I want but it only works if you only write one line.

I understand your frustration with this.

I first learned to program nearly two decades ago using QBasic, which had the awesome LOCATE statement which moved the cursor to any location on the text console. I wrote a whole text-based windowing system with that.

Python's abilities in this area have left me wanting more.

Thermopyle
Jul 1, 2003

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

Shaocaholica posted:

Also, what other not common ways to do stuff are there with Python?

I like that you can use conditionals in list comprehensions.

code:
>>> [row[1] for row in M if row[2] > 3]
[5, 8]
>>> [row[1] for row in M if row[2] > 3 or row[2] == 3]
[2, 5, 8]

Thermopyle
Jul 1, 2003

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

Shaocaholica posted:

I guess another way about it would be to access the disk management module in windows. Not sure if there are any python modules to do that or just resorting to capturing command line stuff.

I think you'd probably get more help with this in one of the Windows threads by just asking about general ways to get the info you need and then figuring out how to implement those ways in Python.

Thermopyle
Jul 1, 2003

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

onecircles posted:

Is python a good language for a beginning programmer that wants to make games?

You can make the games you describe just fine. Additionally, I don't think you'll ever regret having learned Python as it makes a great tool to solve problems. So if in the future you want to move on to C++ or whatever, Python is always going to be there for you with loving arms.

Thermopyle
Jul 1, 2003

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

AzraelNewtype posted:

Doesn't it work as a function by default in 2.6 at least?

No.

Thermopyle
Jul 1, 2003

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

hlfrk414 posted:

What's wrong with
code:
f = open('myfile.txt', 'w')
f.close()
?

I recently started doing:

code:
open('myfile.txt', 'w').close()
Not that it makes any difference, but hey, I just did it 15 minutes ago so I thought I'd throw it out there.

Thermopyle
Jul 1, 2003

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

nbv4 posted:

I looked into that, but it seems to be just for simple one-file scripts. I'm looking for a big installer that will install a bunch of dependencies.

I've used py2exe for a script with something like 10 dependencies or something.

Thermopyle
Jul 1, 2003

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

Lurchington posted:

Here's my interview whiteboard question from the yospos thread: link

questions that stood out, not exhaustive or anything:

On the phone, I was asked:


As a hobbyist programmer that item kind of stood out to me. Why would an employer care if you knew that? What problems does knowing that allow you to solve?

(The link you provided is broken)

Thermopyle
Jul 1, 2003

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

I've been putting off learning web programming because it seemed like it was a completely different ballgame.

I mean, I decided to learn Python a year or 18 months ago, and while Python is completely awesome, the general ideas weren't much different from when I did lots of QuickBasic programming back in the early 90's.

My impression of web programming was that it was a lot different, and I didn't have a firm grasp on how all the pieces fit together. That coupled with the fact that I find any sort of HTML/CSS unfun, just put me off of the whole idea.

Well yesterday, I took the plunge and installed Django and started working through the tutorials.

I should have done this ages ago! As you can tell, I can't compare it to any other web frameworks, but man...Django is sweet stuff.

Just though I'd throw that out there for any other newbish programmers.

Thermopyle
Jul 1, 2003

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

On Windows, trying to pip install packages that require compiling, I always get:

code:
error: Unable to find vcvarsall.bat
That's used for Visual Studio C++, which I did have installed at one point on this computer.

I've now installed mingw, and I have...

code:
compiler=mingw32
...in distutils.cfg.

For some reason it's still trying to use Visual Studio, and I can't for the life of me figure out why.

Anyone have any ideas where else I might look?

Thermopyle
Jul 1, 2003

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

I've used Komodo Edit and WingIDE. Prefer WingIDE, I think.

Thermopyle
Jul 1, 2003

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

Haystack posted:

I really got a lot out of Think Python when I was starting out.

Same.

To give you guys some encouragement...

I went through Think Python like 18 months ago with what amounted to zero modern programming experience. After I finished Think Python, I just went out to make solutions to several problems that I had, and Googled stuff that I didn't know or understand.

I'm definitely not any type of guru, but I'm at the point where I'm contributing to a couple of open-source projects and have released some open-source stuff myself that is being used by others.

Thermopyle
Jul 1, 2003

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

tbp posted:

Any tasks or problems I should set about trying to solve, sort of like how a 5th grader learns math?

The universal answer to this is to write something to solve a problem you have.

After you pick up the basics in Think Python, start solving a problem or automating something you do all the time. Some ideas taken from my projects directory:


1) Write something to organize your download directory.
2) Something to fetch album art for your mp3's.
3) Scrape sports scores/bus schedule/whatever from some website.
4) Write a script to fetch emails and then take actions depending on contents of email. (Remote control your PC!)
5) Same as 4 but with IRC.
6) Fetch your Google Reader shared items and post them to IRC/forum/IM/etc
7) Fetch and graph some data from your modem/router web-admin
8) Organize your photos into folders by date.

Thermopyle
Jul 1, 2003

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

tbp posted:

Lets stick to it and learn this poo poo then. I'll continue with that PDF and soon we'll be taking on those tasks like its not problem

Please do, it's worth it!

Feel free to ask questions. Did the post by First Time Caller help give you an idea what you should be thinking about?

Thermopyle
Jul 1, 2003

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

I'm writing a script to sit between a program's web API (it's XBMC to be specific) and clients that access that API.

For example, you can hit XBMC with...

code:
http://host/xbmcCmds/xbmcHttp?command=setvolume&parameter=5
What I'd like is to direct clients to hit my script with that request and then my script will hit multiple XBMC installations with the corresponding request.

My question is this...what's a lightweight framework/web server that would be good for implementing this? The only thing I'm somewhat familiar with is Django, which just seems too massive for such a thing, besides the fact that the docs constantly say not to use the built-in webserver for anything in production.

I can't imagine any realistic scenario where there would be more than a few clients and a few XBMC installations, so I definitely don't need anything that is meant to handle massive amounts of requests.

niff posted:

I am used to working in visual studio, are there any IDEs for python that aren't too resource intensive for my (soon to be upgraded) 4 year old laptop? Or is it recommended to use notepad++ and a separate compiler so I learn without being auto-corrected?

Give PyCharm a try, people seem to be diggin' it.

Thermopyle
Jul 1, 2003

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

bitprophet posted:

And for the love of God, don't confuse it with the newer project that thought it would be a great idea to name itself "web2py". Totally different (and crap).

Also check out Bottle, which is in the same vein as web.py, to see which one has a more pleasing-to-you API.

I've checked out both Bottle and web.py. I like both of them quite a bit, but settled in to working up some test cases with bottle.

Then I realized that I will probably eventually want basic HTTP auth, and I don't see an easy way to implement that with either of them. :(

Right now I'm looking in to CherryPy. It seems like its a bit more heavy duty than what I really need, but it has basic and digest auth built-in.

Thermopyle
Jul 1, 2003

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

I posted about this before, but I've done some more troubleshooting to no avail...

I'm having a real problem with distutils on Windows that I can't seem to figure out.

So, I have a fresh install of Win7, along with a fresh install of Python 2.7, and an installation of mingw32. I set compiler=mingw32 in the "[build]" section of distutils.cfg.

Any python library that tries to compile something (libxml, numpy, etc) errors out with "Unable to find vcvarsall.bat" which means that it's trying to use Visual Studio to compile.

Through the use of some elite print statements in Lib\distutils\command\build.py, I determined that it is correctly reading the distutils.cfg file to get the compiler option.

The problem is that, I can't quite figure out where in the distutils code it's trying to use Visual Studio instead of GCC. I assume that when when it finds that compiler is set to mingw32 it figures out somehow that it's located at C:\mingw32, but I'm not sure how it does that. I'm not even sure if actually gets to that point. It may read the option in from distutils.cfg and ignore it completely as far as I can tell.

Someone kindly pointed me to a page with a lot of precompiled libraries, but I'm just really interested in figuring out what exactly is going wrong here.

AFAICT, there's some bug in the distutils code causing this, but it's a little out of my expertise to track down what it is exactly.

Thermopyle
Jul 1, 2003

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

Huh, Sikuli looks pretty cool for automating GUI's with Python.

Thermopyle
Jul 1, 2003

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

This feels wrong to me:

code:
def parse_duration(value):
    t = re.search(r"((?P<hour>\d+) hour(s|))? ?((?P<min>\d+) min)? ?((?P<sec>\d+) sec)? ?((?P<ms>\d+) ms)?", value)
    if t:
        hour = 0 if not t.group('hour') else int(t.group('hour'))
        min = 0 if not t.group('min') else int(t.group('min'))
        sec = 0 if not t.group('sec') else int(t.group('sec'))
        ms = 0 if not t.group('ms') else int(t.group('ms'))
        return datetime.timedelta(hours = hour, minutes = min, seconds = sec, milliseconds = ms
Anyone have a better way to change strings that look like the following into timedeltas?

code:
2 hours 13 min 4 sec 312 ms
22 min 4 sec
1 hour 3 min 42 sec
The "ms" is not always present.
It can be "hours" or "hour"
If it doesn't reach hours or minutes then it will only contain up to minutes or seconds, respectively.

Thermopyle
Jul 1, 2003

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

Hypnolobster posted:

Which beginner book should I go with? My only programming experience is extremely unimpressive stuff in the Arduino software and some VB when I was like 13, so the official tutorial is pretty far over my head.

I liked this.

Thermopyle
Jul 1, 2003

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

Rohaq posted:

So, I've got a file I need to parse some details out of.

There are sets of results, separated by '--------------------', I need to parse each of these in order, is there any easy way to do this in Python? In Perl, all I had to do was change the separator variable $/ to whatever I needed, then do a standard for loop on the string containing them. Seems a bit odd if Python doesn't have a built in method or module available to simplify this.

str.split('--------------------')

Thermopyle
Jul 1, 2003

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

bc87 posted:

I just tried it right now and I got this




The syntax is wrong, but I get that I have to make it an integer somehow.

don't use int in the def for printMax.

Use it when you call printMax.

Thermopyle
Jul 1, 2003

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

CrazyPanda posted:

For the function open() is there a way to specify the directory it will look into? i dont want to type in the whole address into the function.

You're using a programming language. Variables are your friend.

Not knowing exactly what your question means...try this...

code:
import os

def openfilesforscience(filename):
    directory = "/some/frickin/directory/"
    with open(os.path.join(directory, filename)) as whatupdudes:
       #do awesome stuff with this file

Thermopyle
Jul 1, 2003

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

GregNorc posted:

I guess I should clarify that I'm not looking to do anything with said html, just strip out the data in a column in a table...

Both of the suggestions provided are good for that.

Thermopyle
Jul 1, 2003

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

What's the practical difference between these?

code:
class WhatUp:
code:
class WhatUp():
code:
class WhatUp(object):

Thermopyle
Jul 1, 2003

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

Yakattak posted:

The first and second one don't inherit any classes, and the last one inherits from object.

Well...duh.

Why would a person care? Is there a difference between the first and second?

Thermopyle
Jul 1, 2003

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

Jarl posted:

With windows it's never a problem, but boy is it a bitch with Linux.

Try installing mysqldb on win7 for Python 2.7.

I ended up having to figure out how to compile it myself, and this is a common problem with it. :(

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

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

Stabby McDamage posted:

In that case, Python may not be your best bet. If there is really and truly no way to use this app other than the GUI, and you simply have to automate this program, then you'd be looking at some kind of GUI-driving macro tool, maybe AutoIt.

He could use AutoIt's COM bindings in python. I gave a little example of how to do that on this StackOverflow answer.

  • Locked thread