|
I assume listEntry is some sort of object? You are adding the same object over and over to the list in ranges. Something like this is what you want to do : code:
Here we are chaning the contents of the list in each loop, and adding that list to the output: code:
code:
|
# ? Feb 27, 2009 06:18 |
|
|
# ? May 9, 2024 06:50 |
|
Yeah, listEntry was an object and I had it outside the for loop. Thanks for the help.
|
# ? Feb 27, 2009 06:25 |
|
darknife posted:Works! code:
Or even better, you can avoid the sqrt altogether, meaning no floating-point calculations if the inputs are integers. Argument unpacking can help make your code more concise as well. code:
Scaevolus fucked around with this message at 08:02 on Feb 27, 2009 |
# ? Feb 27, 2009 07:58 |
|
So I have come across another problem with lists and references it would seem. The problem happens here: code:
|
# ? Feb 27, 2009 22:03 |
|
pankus posted:So I have come across another problem with lists and references it would seem. How are you creating the numData lists? Sounds like all the numData members are referencing the same object. For example, code:
|
# ? Feb 27, 2009 22:27 |
|
Edit:: ^^ This ^^ numData is almost certainly a reference to the same list in every item in ranges. You don't include the code where you assign numData, but make sure you're constructing a new object for each entry in ranges if you want each numData to be different. Again, variables in Python are just labels that point to data somewhere in memory. The equals operator doesn't copy anything but references (at least usually).
|
# ? Feb 27, 2009 22:30 |
|
Thanks again. In my object definition I was setting numData=[] as the default value in the __init__ which was the problem.
|
# ? Feb 27, 2009 22:42 |
|
Please ignore me I am illiterate
Vexed Morgan fucked around with this message at 05:39 on Feb 28, 2009 |
# ? Feb 28, 2009 05:08 |
|
I feel like a moron. How do I modify the original string references so the changes I make are visible outside of this loop?code:
|
# ? Feb 28, 2009 17:39 |
|
sund posted:I feel like a moron. How do I modify the original string references so the changes I make are visible outside of this loop? ljust returns a new string. tag = tag.ljust(len(tag) + 1 + len(tag)%2, '\0')
|
# ? Feb 28, 2009 18:11 |
|
such a nice boy posted:ljust returns a new string. That won't do anything, because you assign the left justified returned string to tag, which is then overwritten at the top of the for loop by whatever's next in the list. Instead, you'll want to build a new list: code:
code:
Benji the Blade fucked around with this message at 19:10 on Feb 28, 2009 |
# ? Feb 28, 2009 19:05 |
|
I'm using Django with Google App Engine and I can't seem to figure out how to display a specific element from a list, when the element index is contained in another variable. I have a list called contentType. It's a simple list with elements 0 through 4. I have a variable (I guess a dict?) called adventure. It's from my datamodel and has a property called contentType, so adventure.contentType is the integer of the index I want to display. I basically want this: contentType[adventure.contentType] But that doesn't work. I can't figure what does. I tried {{ contentType|splice:"3:"|first }} This works and gives me back the 4th element. When I changed it to {{ contentType|splice:"adventure.contentType:"|first }} it just gives me back the 1st element. I can also do {{ contentType.3 }}, which gives me back the 4th element. How can I use a variable there instead of hard coding the number? I guess I could just do this little bit of logic in the python and pass that variable into the template but it seems like there should be a way to do it here, in the template.
|
# ? Mar 1, 2009 11:05 |
|
tayl0r posted:I'm using Django with Google App Engine and I can't seem to figure out how to display a specific element from a list, when the element index is contained in another variable. That's more of a Django question than a Python question, try this thread. EDIT: Could'nt you just use contentType[adventure.contentType] as a template argument? uncleTomOfFinland fucked around with this message at 12:31 on Mar 1, 2009 |
# ? Mar 1, 2009 12:17 |
|
Yeah, doing that little 1 liner in python and just passing it into the template would work just fine. I still think there has to be a way to do it in Django though.
|
# ? Mar 1, 2009 12:37 |
|
Is there a way to run pngcrush in a script? I'm trying to figure out how to crush the pngs after I make them with PIL.code:
|
# ? Mar 1, 2009 18:09 |
|
hitze posted:Is there a way to run pngcrush in a script? I'm trying to figure out how to crush the pngs after I make them with PIL. couldn't you use os.system to run pngcrush from the command line?
|
# ? Mar 1, 2009 18:48 |
|
Modern Pragmatist posted:couldn't you use subprocess.call to run pngcrush from the command line? Fixed.
|
# ? Mar 1, 2009 19:27 |
|
Two related questions: 1. Can someone please compile MySQLdb for Python 2.6 on Windows? On sourceforge a couple of random people have attempted it, but neither of their packages work for me: code:
Thermopyle fucked around with this message at 20:03 on Mar 1, 2009 |
# ? Mar 1, 2009 19:30 |
|
Okay I've been looking to beef up my Python besides just the basics. Best way to do that is to do some of the more mundane problems that I come up with, cleaning data files, data matching and so forth. First, is there something like CPAN or better Rubygems for Python? It's liberating to use something that will install libraries for you without having to do the work manually. Then, is there the 'go to' ORM library for Python, like ActiveRecord for Ruby or Hibernate for Java? This is going to be weird after doing mostly Ruby for about 4 years to a language that discourages metaprogramming.
|
# ? Mar 1, 2009 19:31 |
|
NotShadowStar posted:Okay I've been looking to beef up my Python besides just the basics. Best way to do that is to do some of the more mundane problems that I come up with, cleaning data files, data matching and so forth. You want to look at easy_install http://peak.telecommunity.com/DevCenter/EasyInstall, or pip http://pypi.python.org/pypi/pip (I prefer pip). There is nothing like cpan "baked right into python" as it is commonly felt that external tools can perform the tasks better than something built in. Note that these do build on distutils (the baked in packaging system). So, try out pip. As for ORM's - it depends. Django has it's own, but I think sqlalchemy http://www.sqlalchemy.org/ is the really popular one.
|
# ? Mar 1, 2009 19:58 |
|
edit: ^^ NotShadowStar posted:First, is there something like CPAN or better Rubygems for Python? It's liberating to use something that will install libraries for you without having to do the work manually. The Python Package Index used with EasyInstall, which belongs to the setuptools package, will let you do this sort of thing. If you want to install simplejson, all you have to do is type this: code:
quote:Then, is there the 'go to' ORM library for Python, like ActiveRecord for Ruby or Hibernate for Java? I love SQLAlchemy, mostly because it doesn't force you to use the ActiveRecord model design. There's also the Django ORM, which is ActiveRecord based, but you have to install the whole Django framework to get it. Some people like SQLObject, too.
|
# ? Mar 1, 2009 20:07 |
|
Xenos posted:Some people really hate setuptools, though. Because it's barely maintained, riddled with bugs/etc. Use pip, you'll thank me.
|
# ? Mar 1, 2009 22:44 |
|
m0nk3yz posted:Because it's barely maintained, riddled with bugs/etc. Use pip, you'll thank me. I'll definitely look into it. I've seen somebody mention it on the TurboGears mailing list, but they didn't really talk about why pip is better.
|
# ? Mar 1, 2009 23:00 |
|
This is a good post about it.
|
# ? Mar 1, 2009 23:06 |
|
Bonus posted:This is a good post about it. Good to know. Although I don't get where he thinks gem gets it wrong, because he describes how pip works and that's pretty much how rubygems works, though pip took some of the Rails extensions to gem like freezing and such.
|
# ? Mar 1, 2009 23:59 |
|
Bonus posted:This is a good post about it. Thanks for the link, the responses from Ian Bicking were also good reading. The changes made with pip really do make a lot of sense, like how all the required packages are downloaded before being installed. Seriously, why would you want to install packages any other way? This easy_install "feature" gave me a lot of headaches last summer. I really like the idea of a bundle option. I think that having this option would've made deploying last year's TurboGears 2 alpha to OSX Server a little less painful.
|
# ? Mar 2, 2009 00:16 |
|
setuptools is definitely annoying. I've run into a lot of headaches with it maintaining one particular Python-based application: 1. Customizing distutils commands can cause problems if setuptools comes into the mix. setuptools monkeypatches some things, but not others, so you can run into issues where subclassed commands don't behave properly because you aren't subclassing the setuptools versions. 2. Importing setuptools means you're effectively forcing users to install with setuptools. If they have it installed, it's used. If you remove this import later, subsequent distutils-based installs will never become effective due to how setuptools uses pth files. This can be confusing when people upgrade to a new version of your application and wonder why it still reports being an older version. 3. setuptools provides no way of installing man pages, or any other sort of shared data. easy_install even goes out of its way to "sandbox" the script, preventing it from writing outside of the egg directory. 4. And now my latest issue with setuptools: it seems to completely ignore build subcommands I've added. I have a build_mo subcommand that builds localization files, but with setuptools the command is never run. I still haven't figured out the issue, but suffice to say I loving hate setuptools. I think part of the problem is how distutils itself is designed, but I haven't fully crystallized my thoughts on it yet. I've used pip. It seems okay. One thing that annoys me is that it leaves an empty build directory wherever I run it, which seems incredibly sloppy to me. The fact that there isn't a dedicated forum for it (he says to use the virtualenv Google group), and the very spartan Trac instance that presents you with a blank page by default also seem sloppy. It also doesn't have its own site, instead just using its PyPI page. I'm very skeptical of Ian Bicking in general, having used many of his older projects and being amazed at how over-designed and poorly implemented they were. I've wasted a lot of my time with things like SQLObject, FormEncode, and Paste.
|
# ? Mar 2, 2009 01:21 |
|
So, I'm making an edit to a Pyborg so that it responds to any sentence whatsoever that starts with its name. I'm thinking the best way to go would be to edit this code here:code:
code:
Also, I'd like it to respond if a specific abbreviation (MQ) of its nickname is used at the start of a sentence, but this code: code:
|
# ? Mar 2, 2009 22:14 |
|
Grinnblade posted:if (body.lower.left(self.settings.myname.length()) == self.settings.myname.lower()): missing parens. wrt your last example, you are slicing incorrectly. "mystring"[0:1] will result in "m"; the right index is exclusive. so "the first 2 chars" would be [:2] (note: zero is not necessary, which is why that example right there will work; nor is end-of-string, you can just do e.g. mystr[5:] to get from the 5th char to end of string)
|
# ? Mar 2, 2009 22:31 |
|
Grinnblade posted:
If you haven't read a tutorial already, now is probably a good time!
|
# ? Mar 3, 2009 10:01 |
|
I need to learn a GUI framework for Python, so I was wondering which one is most preferred. Is there any reason not to use PyQt4 for application and GUI development? Or is one of the other standard tool-kits (GTK, wxPython, Tkinter) more commonly used and accepted? My current shop uses Qt3 and 4 in C/C++, so I figured Qt in Python might be a good place for me to start. Any suggestions? Thanks.
|
# ? Mar 3, 2009 23:14 |
|
If you already know Qt, using it in Python is by far your best move. If you're good with Qt Designer, you can convert its ui files into usable python with a single command and then just run from there. It's all very familiar.
|
# ? Mar 4, 2009 00:17 |
|
AzraelNewtype posted:If you already know Qt, using it in Python is by far your best move. If you're good with Qt Designer, you can convert its ui files into usable python with a single command and then just run from there. It's all very familiar. Sorry, I should have clarified. I, personally, don't know Qt yet, or any other toolkit. Just getting started with GUI work in general. Most of my work has been limited to the console or very, very basic Tkinter.
|
# ? Mar 4, 2009 04:38 |
|
It's really not that hard to pick up, and the rest of your shop should have no trouble reading it and helping out as it's a pretty literal conversion from C++ to Python for most of the stuff. It's probably not necessarily any better or easier than wxPython (which I think is the common choice) but there's definitely something to be said for having living resources. Outside of some very, very limited AWT experience, Qt was the first GUI toolkit I really looked at and I really quite liked it. The python wrapper does nothing to hurt the positive aspects of it, and it removes some of the dumber bits (extensive preprocessor magic).
|
# ? Mar 4, 2009 06:33 |
|
Another thing... my two dead tree references for Ruby are The Ruby Programming Language and The Ruby Cookbook. Combined they're all I need. I use a similar set for Perl except I used the unholy trinity of The Llama, The Camel and The Cookbook. What's the combination for Python that's similar? The Python Recipes book has a rabbit on the cover. Cute.
|
# ? Mar 4, 2009 18:26 |
|
I've looked around, and I can't find any resources for programming an ascii based tile game engine in Python. Essentially, I want to create an RPG tech demo with a fixed game world (Not randomly generated as in a Roguelike). Imagine a top-down jRPG such as Final Fantasy 1, but with ascii tiles rather than graphical tiles. Can anyone help me out with the concepts here? I don't know how to go about both displaying a map from a text file and then dynamically updating it based on events and whatnot. Some starter advice on how to approach the problem is all I need for now.
|
# ? Mar 5, 2009 17:38 |
|
Here's my newbie python question. I'm writing a small script to telnet over to a particular device, run a few checks and then run a few commands. The issue - the checks. The checks will run commands, and display status/results. I need to get those results in order to continue or abandon the script depending on the status. For example, this isn't the actual command needed, but it gives you an idea of what I'm looking for: command - ifconfig parsing through results to find a particular string, say... "Loopback" If Loopback is present, I will continue, else, abandon. p.s. - fyi, there's no grep on the remote device, nor can it be implemented. It is just a standalone device that has a limited number of device specific commands. Schatten fucked around with this message at 21:19 on Mar 5, 2009 |
# ? Mar 5, 2009 20:23 |
|
Centipeed posted:I've looked around, and I can't find any resources for programming an ascii based tile game engine in Python. Essentially, I want to create an RPG tech demo with a fixed game world (Not randomly generated as in a Roguelike). I think you want to check out the pycurses module
|
# ? Mar 5, 2009 23:58 |
|
Schatten posted:Here's my newbie python question. Check out paramiko, pexpect and the like, you're going to need to issue a command, get the output, parse and choose, and then reconnect
|
# ? Mar 6, 2009 00:37 |
|
|
# ? May 9, 2024 06:50 |
|
Schatten posted:I'm writing a small script to telnet over to a particular device, run a few checks and then run a few commands. The issue - the checks. The checks will run commands, and display status/results. I need to get those results in order to continue or abandon the script depending on the status. Big, important question: is it literally telnet, or is it SSH? The following only applies to SSH. For Telnet you'd need to use Python's builtin telnet lib, I think, as I'm not aware of higher level tools that aren't SSH specific. (Condolences if you are working with a telnet-only device, I assume it's very resource constrained or very old...?) So, assuming SSH: you could do what m0nk3yz suggests, but I think Fabric is a much better idea; having a newbie wrestle with Paramiko and Pexpect doesn't sound like the best idea IMHO. I contributed a big overhaul of Fabric's capability last year specifically so it can do this kind of thing; no other "deploy" related tools were able to (long story; they could do e.g. run('ifconfig') but weren't able to get the result back, or do logic based on the result). Here's an example fabfile based on your example: code:
|
# ? Mar 6, 2009 01:46 |