|
Ok, so a question for all of you. I'm moving forward with a project to design a ton of function tests in Nose - the problem being, each test needs to be "told" about the attributes of the system under test (ip addresses, etc). I can do a few things:
|
# ? Jul 7, 2008 21:47 |
|
|
# ? May 11, 2024 16:00 |
|
How about you just write it into a dict in Python syntax and then import the dict? edit: or just set variables and then import the module. You know, like if you have test_settings.py and then in it you do code:
hey mom its 420 fucked around with this message at 22:15 on Jul 7, 2008 |
# ? Jul 7, 2008 22:08 |
|
Wow. After being recommended pyGame over in the Game Development thread, I have been trying to figure out how to get python / pygame and setup with a decent IDE on Mac OSX. Can anyone point me in the direction of a simple step by step tutorial to getting things up and running? All the stuff on the pygame website is pretty advanced.
|
# ? Jul 7, 2008 23:49 |
|
Hanpan posted:Wow. After being recommended pyGame over in the Game Development thread, I have been trying to figure out how to get python / pygame and setup with a decent IDE on Mac OSX. Did you try http://rene.f0o.com/mywiki/PythonGameProgramming? It looks pretty reasonable.
|
# ? Jul 8, 2008 00:20 |
|
Hanpan posted:Wow. After being recommended pyGame over in the Game Development thread, I have been trying to figure out how to get python / pygame and setup with a decent IDE on Mac OSX. I always check PythonMac for packages first when installing a big package. These are nice tested pkg installers for OS X that have always worked goldenly for me. PyGame is included there http://pythonmac.org/packages/py24-fat/index.html
|
# ? Jul 8, 2008 00:33 |
|
I have been trying to script a little bit with Python on Windows XP but I have run into this weird problem I can't figure out.code:
Any regular commands like 'dir && pause' work fine too.
|
# ? Jul 8, 2008 07:16 |
|
Pavol Paska posted:I have been trying to script a little bit with Python on Windows XP but I have run into this weird problem I can't figure out. It's probably trying to read something from stdin, which is set up right in the interactive shell but not when running as a script. (I'm guessing from your description, that is, I'm not actually sure when stdin is set up and not set up under Windows.) Try running it as "python -i /your/script/name" and see if that fixes it. It should run and then give you the interactive shell.
|
# ? Jul 8, 2008 16:20 |
|
I ran into an issue when attempting to retrieve a slice from a container class I had created. The docs seem to imply that __getslice__() has been deprecated since 2.0 so I didn't bother to declare it in my class definition. However, once I added it my code magically worked. What gives? I can see why it would be deprecated as __getitem__ should be enough to pull a slice. But why is that bit about deprecation in the docs if I still have to declare it? Is that just wishful thinking?
|
# ? Jul 8, 2008 17:22 |
|
bosko posted:Has anyone gotten PayPal IPN working with Python? For the life of me I can't figure out what I am doing wrong when I have simply taken the idea from another (working) script and used it in my own. Paypal are the devil. Do not trust your business to those cunts. Seriously, I blame their worthless system for my current unemployment.
|
# ? Jul 8, 2008 18:51 |
|
No, __getslice__ is deprecated, don't use that. Make sure that you have a new-style object there. So if you havecode:
code:
|
# ? Jul 8, 2008 18:54 |
|
Flea110 posted:I've spent the last week or so writing a battle simulator for the board game Axis & Allies. I'm fairly new to programming, and it's my first program that uses classes. Its not bad, but I get the feeling your still sort of writing structured code just wrapped in objects. Its still a valid way of coding, but its not the best way. Heres how to look at objects and do it right;- Disclaimer: I'm an OO Design zealot, so take this with moderation if you don't want to grow an absurd neckbeard and start developing erections at the mere mention of smalltalk. An object is a little black box, that you can make lots of copies of, and it has properties and methods. Methods being best thought of as "code that happens when an object is sent a message" (You send the message by calling the method). All understood right? One needn't care whats *in* the black box, as long as the properties and methods behave as expected. A black box is a model of a thing, an object , so to speak. Your program is an object. The Countries are objects, the board pieces are objects. The players are objects And so on. So you might for instance write a country object that has a property like "who is occupying me?" and "How many troops are here". And then perhaps add methos like "add_troops([list of troop objects],player,where_troops_came_from)" or "send_troops([list of troop objects],player,where_troops_go_to)", then maybe methods like "calculate_sovereignty" and "make_dudes_fight" or whatever and so on until you have a model of how a country in the game follows the rules and gains/loses sovereignty and so on. Then you do the same for troops/units And add a player object (maybe you make this first) and finally add a game object that controls and contains all the other guys. With all that finished you might then create some objects that interact with the user. It does sound like more work, but once you get the hang of it, its really intuitive, and it becomes second nature, and it fits neatly with the sort of methodologies you might work with in the 'serious programming world' like unit testing and UML and poo poo like that.
|
# ? Jul 8, 2008 19:02 |
|
JoeNotCharles posted:It's probably trying to read something from stdin, which is set up right in the interactive shell but not when running as a script. (I'm guessing from your description, that is, I'm not actually sure when stdin is set up and not set up under Windows.) Didn't fix it but for some bizarre reason using robocopy.exe instead of just robocopy works. I really love windows commandline tools sometimes. Thanks anyway
|
# ? Jul 9, 2008 08:59 |
|
outlier posted:What are people using for general HTML form generation? A lot of the more popular modules out there are tied to particular frameworks (e.g. zope.form, newforms). I really like formencode's validation and conversion but it doesn't generate forms (for good reasons) and has some oddities when handling arrays of fields. formbuild is supposed is okay, but again has a couple of odd design decisions. You might want to look into ToscaWidgets, which is based on the TurboGears widgets package. It isn't actually dependent on TurboGears, though. I personally haven't used this, but it's going into TurboGears 2, and if it works anything like the original TurboGears widgets package, it'll work really well with FormEncode.
|
# ? Jul 10, 2008 06:41 |
|
I'm new to python and i'm working on the Euler questions as a way to practice. I haven't touched programming in a few years and just started getting back into it, so forgive me if this is a stupid question. I need to check if a number is divisible by the numbers 1 through 20. http://pastebin.com/m61c9119d (probably cringe-worthy code) I'm not sure if the way I'm doing it really works, and i'm kind of stuck on how to do so. If anyone could give me advice or point me in the right direction without writing 20 separate if statements, that would be awesome.
|
# ? Jul 14, 2008 07:31 |
|
Phiberoptik posted:I'm new to python and i'm working on the Euler questions as a way to practice. I haven't touched programming in a few years and just started getting back into it, so forgive me if this is a stupid question. You mistyped range() at least. Use 2,21, not 2-21. EDIT: Check is referenced before its assigned too. EDIT: This little snippet returns a list that contains all the numbers between 2 and 20 x is divisible by: code:
uncleTomOfFinland fucked around with this message at 08:34 on Jul 14, 2008 |
# ? Jul 14, 2008 08:26 |
|
Pavol Paska posted:You mistyped range() at least. Use 2,21, not 2-21. Thanks! I had check assigned, but didn't include it in the pastebin. I'll tinker with this and see how it goes. edit: I'm trying to use sqrt for a problem, but I keep getting this error: code:
RyceCube fucked around with this message at 11:23 on Jul 14, 2008 |
# ? Jul 14, 2008 09:03 |
|
did you import math? something like code:
|
# ? Jul 14, 2008 11:58 |
|
Because I'm a pedant: to do it somewhat more neatly and avoiding some namespace clutter,code:
|
# ? Jul 14, 2008 16:36 |
|
Help me out, y'all; I'm preparing for a job interview this afternoon and I'm trying to think of all the questions they could possibly ask. I know that "what feature would you most like added to language X" is a popular question, but I can't think of anything for Python. So...what feature would you most like added to Python?
|
# ? Jul 14, 2008 16:43 |
|
such a nice boy posted:Help me out, y'all; I'm preparing for a job interview this afternoon and I'm trying to think of all the questions they could possibly ask. I know that "what feature would you most like added to language X" is a popular question, but I can't think of anything for Python. So...what feature would you most like added to Python? One of the strange things about Python is that the things that used to bug me have mostly been fixed over the years. Still, here's some outstanding items: * There's a bunch of ubiquitous and widely used 3rd party libraries that really should be in the standard library. I'm thinking of PIL, more advanced database interaction (something like JDBC), a better standard GUI than Tk and so on. * Not everyone uses them, but it would be neat to have interfaces as part of the standard library (rather than the complex monolith that is zope.interface). * Lot's of people hate using 'self' in objects. Personally, I'm indifferent. * In-place increment and decrement (x++, x--) would be nice. * Unicode as the standard string would be nice, and that's coming in Python3000. * Multi-line and more sophisticated lambdas, oh yes.
|
# ? Jul 14, 2008 17:38 |
|
Spazmo posted:Because I'm a pedant: to do it somewhat more neatly and avoiding some namespace clutter, Technically this doesn't actually avoid any namespace clutter, both approaches add a whopping one new name to the local namespace However, this approach does save typing if you use the imported function many times.
|
# ? Jul 14, 2008 17:54 |
|
Python's lambdas are perfectly capable. They're meant for quick one statement functions that you pass to other functions. If you need more than one statement, you just make a function and pass the function. I honestly don't understand why there's been so much whining over them, and I'm not really sure why Guido even considered removing them in the first place.
|
# ? Jul 14, 2008 17:57 |
|
such a nice boy posted:So...what feature would you most like added to Python? where/with: code:
|
# ? Jul 14, 2008 18:03 |
|
Spazmo posted:Because I'm a pedant: to do it somewhat more neatly and avoiding some namespace clutter, Do you happen to like PHP by any chance?
|
# ? Jul 14, 2008 19:01 |
|
Pavol Paska posted:Do you happen to like PHP by any chance? In his defense, doing from math import sqrt is perfectly Pythonic; the "lulz PHP's approach is awsum!" attitude would be closer to from math import *
|
# ? Jul 14, 2008 19:59 |
|
Pavol Paska posted:Do you happen to like PHP by any chance? Never done any, and I'm told I should be happy about it. I just don't like typing math.sqrt(whatever) all the time. I suspect what you mean is that it's better if I know where the sqrt function comes from when I'm calling it, and I tend to agree, but if I'm just doing something on the Python console, the extra keystrokes are a bit annoying.
|
# ? Jul 14, 2008 21:25 |
|
bitprophet posted:In his defense, doing from math import sqrt is perfectly Pythonic; the "lulz PHP's approach is awsum!" attitude would be closer to from math import * import * isn't inherently bad, but you generally shouldn't use it for modules that aren't designed for it (i.e. they don't have __all__ set). It can also confuse some lint tools like PyLint and Pyflakes and make it harder to statically find undefined names.
|
# ? Jul 14, 2008 23:31 |
|
Milde posted:import * isn't inherently bad, but you generally shouldn't use it for modules that aren't designed for it (i.e. they don't have __all__ set). It can also confuse some lint tools like PyLint and Pyflakes and make it harder to statically find undefined names. Oh, certainly, I was simply pointing out that if one is going to try and draw parallels between a given Python import syntax variant, and PHP, the "import *" one is closest to PHP's "haha namespacing what's that". My rule of thumb is generally to use the * when I hit a confluence of A) using the imported names more than two or three times each and B) needing more than, say, 3 or 4 of the names within the module in question. In a semi related note, I'm embarrassed to admit that I only really "got" PEP8 about a month or two ago (despite being primarily a Python coder for the past 4 years), and until then would sort of haphazardly mix things up. Still not a PEP8 saint but I've got the basics (e.g. foo, bar instead of foo,bar) down pat and it actually does make a difference in terms of the overall feel of the code.
|
# ? Jul 15, 2008 01:15 |
|
bitprophet posted:In a semi related note, I'm embarrassed to admit that I only really "got" PEP8 about a month or two ago (despite being primarily a Python coder for the past 4 years), and until then would sort of haphazardly mix things up. Still not a PEP8 saint but I've got the basics (e.g. foo, bar instead of foo,bar) down pat and it actually does make a difference in terms of the overall feel of the code. I've been using Python for about 2 years and I've been using nearly everything in PEP8 since the beginning, probably due to the book I was learning from (Learning Python). The only thing I had been doing differently was using lowerCamelCase for variable names. I just switched to underscored variables and it *feels* more Pythonic. Which probably sounds weird. But it does. I don't know.
|
# ? Jul 15, 2008 11:48 |
|
Quick Python question. I'm presently working on a project which requires (and in fact is made much nicer by) the use of large databases. After a quick look, I think I might use Python/MySQL mostly because it is free and rather easy to use, however, I'm open to any suggestion. I don't really need a very elaborate database system just something robust, easy to use and manage. The application is not related to the web in any shape or form so "security" is not an issue at all. Any good names to look up? e:SQLite seems a solution I hadn't explored at first, any ideas about it? A Perturbed Parrot fucked around with this message at 05:09 on Jul 21, 2008 |
# ? Jul 21, 2008 04:48 |
|
A Perturbed Parrot posted:e:SQLite seems a solution I hadn't explored at first, any ideas about it? SQLite is a very good choice if you need the features a database offers, but you don't need to have extremely high performance or support a huge load. With a proper database abstraction layer, you can make it so that the choice between SQLite/MySQL/PostreSQL/whatever is just a configuration option. Scaevolus fucked around with this message at 05:52 on Jul 21, 2008 |
# ? Jul 21, 2008 05:31 |
|
I'm attempting to compare data in the format "Sat, 12 Jul 2008 20:37:43 GMT -0500" to gmtime() with strptime(). Right now I have "%a, %d %b %Y %H:%M:%S %Z", but Python doesn't seem to have a time directive to handle the numeric GMT offset properly. What could I do to make this work, or am I even going about it in the best way?
|
# ? Jul 21, 2008 06:14 |
|
A Perturbed Parrot posted:Quick Python question. The only problem I've found with Python and MySQL is getting the library (MySQLdb) to compile. If you can pass that hurdle, it's fine. The Python Postgres libraries are okay. SQLite, although supposedly a dumb and simple solution works absolutely fine, is easy to use and performance is okay. You may want to think about a database wrapper or ORM like SQLObject or SQLalchemy. It takes a while to get the hang of them but it makes it easy to change your db and deal in objects instead of rows.
|
# ? Jul 21, 2008 08:42 |
|
I've just discovered the wonders of appscript, a way to call Applescript from Python. It's cool, and recommended as much better than using Applescript directly. I hacked up a quick script to import a list of todo items into an application without an explicit Applescript dictionary. You can see it here, including some notes on a few holes or oddities I found.
|
# ? Jul 21, 2008 10:09 |
|
I have an odd problem. I have a RPC that is returning a dictionary but, unfortunately the dictionary is coming back as a string. It's a valid dictionary but, basically the __str__ version of the dict. How can I cast the string back into a dictionary :\
|
# ? Jul 24, 2008 05:30 |
|
ATLbeer posted:I have an odd problem. I have a RPC that is returning a dictionary but, unfortunately the dictionary is coming back as a string. It's a valid dictionary but, basically the __str__ version of the dict. I can't think of anything other than eval() or a similarly hacked-up parser :/
|
# ? Jul 24, 2008 05:33 |
|
Scaevolus posted:I can't think of anything other than eval() or a similarly hacked-up parser :/ I guess that technically works
|
# ? Jul 24, 2008 05:40 |
|
If you have to resort to that, you might want to do eval(x, {'__builtins__': ''}). That gets a little more complicated if you have objects that don't have literal representations, of course.
|
# ? Jul 24, 2008 07:17 |
|
ATLbeer posted:I guess that technically works Is there any reason why you aren't using pickle to pass the objects around? Or, if the dicts are simple enough, something like json.
|
# ? Jul 25, 2008 00:20 |
|
|
# ? May 11, 2024 16:00 |
|
For those of you using nose, I uploaded a new configuration data plugin yesterday: http://pypi.python.org/pypi/nose-testconfig/ It's a quick and dirty method of passing configuration data down to tests from within the context of nose.
|
# ? Jul 29, 2008 12:35 |