|
Oh, I didn't realize that ElementTree was part of the standard library now. I guess it's bad to use regular expressions to parse xml like this, but I figured it wasn't worth installing a new module just for this. Never mind then. Edit: vvvvv Personally, that's the point where I would start to just use regular expressions and hope nobody notices. mystes fucked around with this message at 23:50 on Apr 14, 2009 |
# ? Apr 14, 2009 23:20 |
|
|
# ? May 23, 2024 17:15 |
|
mystes posted:Oh, I didn't realize that ElementTree was part of the standard library now. I guess it's bad to use regular expressions to parse xml like this, but I figured it wasn't worth installing a new module just for this. Never mind then. If elementtree isn't available, then use the DOM implementation -- it's really ugly, since it's basically just a port of the Java API, but still usable.
|
# ? Apr 14, 2009 23:42 |
|
Janin posted:http://docs.python.org/library/xml.etree.elementtree.html Awesome, thanks. This worked perfectly!
|
# ? Apr 15, 2009 17:31 |
|
Let me preface this post by saying I am a complete nooblet when it comes to programming, so don't laugh too hard. I am looking for some feedback on this little bit of code I wrote. It creates a 2-D grid that I am going to use with a battleship game I am programming for practice.code:
code:
|
# ? Apr 16, 2009 02:30 |
|
You seem to be using lists, why not just have a 2D list?code:
|
# ? Apr 16, 2009 02:50 |
|
I don't know if anyone here is interested, but I've been working on a benchmark written entirely in Python, and I need people to mess with it and find bugs. http://forums.somethingawful.com/showthread.php?threadid=3119056
|
# ? Apr 16, 2009 08:15 |
|
So I need to search through a few hundred (500-1000) text files for a simple string (4-20 chars). I'm not counting, its basically true once I find the first occurance. This is on windows so no access to native grep. What can I do to make it somewhat fast as opposed to scanning through the file starting at the beginning?
|
# ? Apr 16, 2009 21:11 |
|
Shaocaholica posted:So I need to search through a few hundred (500-1000) text files for a simple string (4-20 chars). I'm not counting, its basically true once I find the first occurance. This is on windows so no access to native grep. What can I do to make it somewhat fast as opposed to scanning through the file starting at the beginning? download and install unxutils! otherwise read and adapt effbot's widefinder deimos fucked around with this message at 21:32 on Apr 16, 2009 |
# ? Apr 16, 2009 21:28 |
|
outlier posted:I have a webpage with a form (on a Plone site for what it matters), that when submitted calls an external program to do some calculations, grabs the results and renders them on the page. Simple. (For interest, it's matching submitted biosequences to an established corpus via various specialised commandline programs.) Odd to follow myself up but ... The situation is that I have some 3rd party code calling a commandline program, waiting for the results, then munging them in various ways before returning them to a webservice. And when the user gets bored and terminates the request, the called commandline process seems to hang around. Curious. Dwelling through the code, I see they have called the commandline with the subprocess module. I would reason that when owning object (that calls subprocess and creates the Popen) gets deleted, then the Popen should get deleted and delete the process - yet it's still hanging around. What gives? How can I ensure that a called process is disposed of correctly?
|
# ? Apr 17, 2009 15:06 |
|
Can anyone explain XML parsing to me? I look at XML and think its pretty simple but all the modules and tutorials I read seem extremely esoteric. I just want to grab values from certain tags which shouldn't seem this complicated with all kinds nodes and poo poo.
|
# ? Apr 17, 2009 18:29 |
|
Sylink posted:Can anyone explain XML parsing to me? I look at XML and think its pretty simple but all the modules and tutorials I read seem extremely esoteric. That's really a general programming question not a Python one but look: an XML document is a set of nested tags that can be represented as a tree. So you _have_ to think about nodes, because to get to the node you want, you need to walk to the right point in the tree. But that's no so hard, because you just start from the root and move to children, and their children as you need. Additional free advice: use xml.etree (in Python 2.5+) or Elementtree (before that). It make handling XML easy.
|
# ? Apr 17, 2009 19:14 |
|
Sylink posted:Can anyone explain XML parsing to me? I look at XML and think its pretty simple but all the modules and tutorials I read seem extremely esoteric. Here's how you read the temperature from Google's API: The XML document is here: http://www.google.com/ig/api?weather=Denver To print the current temperature, you can do: code:
Scaevolus fucked around with this message at 19:33 on Apr 17, 2009 |
# ? Apr 17, 2009 19:18 |
|
So coming from PHP I'm spoiled with the most excellent online documentation ever. Is there a wiki-like documentation site for Python anywhere that is nearly as comprehensive? I'm finding plenty of samples here and there, and the python site walks through a lot of ideas, but I'd like something that works more like reference material than step-by-step walkthroughs.
|
# ? Apr 17, 2009 19:29 |
|
I know this will sound facile, but have you looked at the standard documentation for python? http://docs.python.org/index.html It has the complete language reference: http://docs.python.org/reference/index.html And the complete library reference: http://docs.python.org/library/index.html
|
# ? Apr 17, 2009 19:38 |
|
tef posted:I know this will sound facile, but have you looked at the standard documentation for python? Actually, somehow I missed the larger spectrum of information there. That will be a help, but I'm really more curious to know if anything community-driven (ala PHP's documentation) exists. I love the ability to look up a function on php.net then glance down to the user comments to see some developer who's done exactly what I'm looking to do and provides a code sample.
|
# ? Apr 17, 2009 20:15 |
|
Ferg posted:Actually, somehow I missed the larger spectrum of information there. That will be a help, but I'm really more curious to know if anything community-driven (ala PHP's documentation) exists. I love the ability to look up a function on php.net then glance down to the user comments to see some developer who's done exactly what I'm looking to do and provides a code sample. We're adding comments to the docs soon, I don't know when though
|
# ? Apr 17, 2009 20:48 |
|
So I have an interesting bug. My programs were working fine until all of a sudden they decide not to find the module they require anymore. If I move the source files to my desktop lets say they run fine. However, If I run one in the original directory I get an error as if all of the other py files in the directory ran too and they complain the module doesn't exist. For example: code:
I get the same poo poo if I run another py file diggtest.py which for some reason decides to call xml.py code:
This really is pissing me off. And these files all worked 5 minutes ago and as far as I know nothing changed. This is under python 2.5
|
# ? Apr 17, 2009 21:08 |
|
Sylink posted:So I have an interesting bug. in digg.py, xml.dom will find xml.py in it first and look for a dom module in it, the current directory is searched first in the python path
|
# ? Apr 17, 2009 21:12 |
|
I have a loop which adds entries to a dictionary like so:code:
What I'm expecting is to iterate through this DICTIONARY, get its LIST value, iterate through the LIST and extract the values based on their index. Would I be better off with a multi-dimensional list here instead of a dictionary? The following code is just giving me the first and second letter of the name. code:
|
# ? Apr 17, 2009 21:12 |
|
No Safe Word posted:Don't name the file xml.py Oh god I love you, I've been swearing at my computer for the last ten minutes. My aneurysm subsided. I'm a decent programmer but 99% of my problems turn out to be stupid/simple.
|
# ? Apr 17, 2009 21:14 |
|
Sylink posted:This makes no loving sense and is annoying. If I move diggtest.py and my library digg.py to the desktop they run fine. If I open up a new command line and do from xml.dom import minidom the command works Look at what's happening here with the relationship between module names and filenames: code:
|
# ? Apr 17, 2009 21:14 |
|
mister_gosh posted:I have a loop which adds entries to a dictionary like so: 2) you don't need that inner loop once you have the id, just do: code:
|
# ? Apr 17, 2009 21:17 |
|
No Safe Word posted:1) no, you don't need to instantiate variables Love for python rising! Java would never allow you to do this sort of thing, but it makes complete sense. So if you call another .py program, would that program be aware of the variable names (labels) you initially assigned the indexes as?
|
# ? Apr 17, 2009 21:22 |
|
mister_gosh posted:Love for python rising! You would probably want to pass them as parameters to a function, not make them global to another module. code:
|
# ? Apr 17, 2009 21:33 |
|
mister_gosh posted:Love for python rising! I'm not sure I understand what you are asking, what do you mean by call a .py program, you mean load the module? When you load a module, it's code is run, and whoever imports the module gets a module object which contains whatever the module defined. Also, make sure you understand python scope, it is different from Java and the C family of languages. When a variable is declared in a function, it is accessible to the whole function. code:
|
# ? Apr 17, 2009 21:43 |
|
Screw that:code:
|
# ? Apr 17, 2009 22:44 |
|
I'll start by saying I am very new to Python and programming in general, and know nothing about making a GUI. I've decided to start a very simple project of building a ledger of some sort to keep track of my spending and balances. I would like to eventually learn how to put it into a very simple GUI. My question is if I write the program to work in a console window, is it typically easy to come back later on and write a GUI interface to interact with the already established program? Or should I just start writing the program with a GUI interface from ground zero because trying to incorporate it later would be a pain.
|
# ? Apr 17, 2009 23:45 |
|
If you pay a lot of attention to the architecture of your program it should be fairly easy to add a GUI later(this is, strictly speaking, how an app with a GUI *should* be). However in practice this it isn't going to be totally easy for someone new to programming to know what to watch out for. So my advice would be write it for the shell first, and try to divide your functions into 2 groups, those that interact with the user, and those that interact with the actual representaiton of the data. If you do that you should be in a good position.
|
# ? Apr 17, 2009 23:47 |
|
I would read up on how GUIs work first, so that you have an idea of how to structure your program in a way that would be easy to add a GUI.
|
# ? Apr 18, 2009 02:04 |
|
BeefofAges posted:I would read up on how GUIs work first, so that you have an idea of how to structure your program in a way that would be easy to add a GUI. Thanks guys. Any recommended readings?
|
# ? Apr 18, 2009 02:39 |
|
What's a quick way to simulate probability? If I'm given a probability of say, 0.7, I want to do something 70% of the time (and not do said thing 30% of the time)
|
# ? Apr 19, 2009 04:38 |
|
Tomed2000 posted:What's a quick way to simulate probability? If I'm given a probability of say, 0.7, I want to do something 70% of the time (and not do said thing 30% of the time) code:
|
# ? Apr 19, 2009 04:46 |
|
what is popular for python GUI usage these days? Is it still tkinter or whatever? I'd like to make something quick and easy for windows but cross platform is fine. I just want it easy to make.
|
# ? Apr 19, 2009 05:30 |
|
hi everyone, im trying to install numpy 1.3.0 into my python version 3.1 but its not working. i have no idea what to do with the contents of the zip file. where do i put them? do they go into the python directory? but where? inside the library folder? when i tried importing numpy after copying them into the lib folder i got the following error File "<pyshell#0>", line 1, in <module> import numpy File "C:\Python31\lib\numpy\__init__.py", line 117 except ImportError, e: any ideas on what i may be able to do?
|
# ? Apr 22, 2009 04:50 |
|
I'm fairly certain numpy, like most major python libraries, hasn't ported to 3k yet.
|
# ? Apr 22, 2009 05:50 |
|
king_kilr posted:I'm fairly certain numpy, like most major python libraries, hasn't ported to 3k yet. king_kilr is correct. There's a GSoC project to port it, I think
|
# ? Apr 22, 2009 14:25 |
|
hi everyone, im a hobbyist programmer and i really like what i have seen of python so far. i really want to understand the language but i am not getting that through reading through the documentation. i learn best through solving problems and working on projects. are there any challenge puzzles or problem sets out there to help facilitate one's understanding of python?
|
# ? Apr 23, 2009 05:47 |
|
CrazyPanda posted:hi everyone, im a hobbyist programmer and i really like what i have seen of python so far. i really want to understand the language but i am not getting that through reading through the documentation. i learn best through solving problems and working on projects. are there any challenge puzzles or problem sets out there to help facilitate one's understanding of python? http://projecteuler.net/
|
# ? Apr 23, 2009 05:50 |
|
A A 2 3 5 8 K posted:http://projecteuler.net/ I tried Project Euler when I was first getting into a programming language, but the problem is that most of the thinking you have to do (Or I had to do, at least) was mathematical rather than "How do I do this with the language I've got in front of me?". Did anyone else find this?
|
# ? Apr 23, 2009 15:23 |
|
|
# ? May 23, 2024 17:15 |
|
Centipeed posted:I tried Project Euler when I was first getting into a programming language, but the problem is that most of the thinking you have to do (Or I had to do, at least) was mathematical rather than "How do I do this with the language I've got in front of me?". Did anyone else find this? That's fair comment - a lot of the problems are mathematical or algorithmic in nature. It's a good source of exercises, but don't feel that you have to do every problem.
|
# ? Apr 24, 2009 18:43 |