|
Centipeed posted:I was looking at GUI programming with Python, but I figured I'd just ask here instead of wading around the internet trying to find an answer: Do any of the Python GUI doohickies work in the same way the visual programming languages work, like VB.net and C#? As in, you can just drag and drop GUI components and then put your code in behind the scenes, as it were? Boa constructor is a full blown delphi/vb type system for python. Its a bit undermaintained and has some quirks however. Its a very impressive piece of code and if the guy behind it wasnt so bad at letting other people work with his code, it'd be *the* IDE for python work bar none.
|
# ? Dec 28, 2008 18:31 |
|
|
# ? May 18, 2024 10:08 |
|
No Safe Word posted:That's because: It spit out the right answer in a split second. Welcome to Costco, I love you.
|
# ? Dec 28, 2008 19:37 |
|
nbv4 posted:In Django, you can format dates in the template system by using PHP-style date format strings like so: "{{ my_date|"n-j-Y" }}" but how do you do the same thing from within python itself? I know about datetime.date.strftime() and strptime(), but those functions take a completely different date formatting "language"... When in doubt... browse source http://code.djangoproject.com/browser/django/trunk/django/utils/dateformat.py code:
|
# ? Dec 29, 2008 20:13 |
|
Ok so I'm trying to write a program which basically allows me to input questions and their answers, organized by chapter/book/whatever so I can study them. Like flashcards. The problem is I'm not sure how I should be storing them. I'm guessing that using a database is the way to go instead of reading/writing from a text file, but I'm extremely new at all this programming stuff and I can't figure out how to use databases with python. I have installed MySQL but the one module I can find that supposedly lets use work with MySQL doesn't seem to work with Python 2.6. I guess I could obviously downgrade the version I'm using, but I really have no idea if I'm even walking down the right path. Any tips?
|
# ? Jan 1, 2009 18:12 |
jstirrell posted:Ok so I'm trying to write a program which basically allows me to input questions and their answers, organized by chapter/book/whatever so I can study them. Like flashcards. The problem is I'm not sure how I should be storing them. I'm guessing that using a database is the way to go instead of reading/writing from a text file, but I'm extremely new at all this programming stuff and I can't figure out how to use databases with python. I have installed MySQL but the one module I can find that supposedly lets use work with MySQL doesn't seem to work with Python 2.6. I guess I could obviously downgrade the version I'm using, but I really have no idea if I'm even walking down the right path. If you have a metric fuckton of questions and answers that are being updated and changed constantly and actively, a database might be the way to go. Here, however, it seems like a better idea to go the simple route and just have a .txt file with a few special tags in it. Especially if you're just learning how to program. Since you're just starting to program, I'd recommend building the program iteratively, rather than designing all the little chunks and putting them together. First, write something that can take input and dump it back to the screen. Second, write something that can take input and dump back everything that has been entered so far. Next write something that will take input and write it to the disk. Afterwards, write something that will take input and dump to console everything that has been written to disk and the console. When you're comfortable enough that you understand these parts, build a data structure that can hold your question and answer. Find a way to write it to and read it from the disk. When all that's done, build the interface. ( A)dd question R)eview chapter, etc ) Don't hesitate to write pseudocode on a napkin. Startup: Load q/a list while( !quit ) - show menu end while save q/a list Jo fucked around with this message at 18:55 on Jan 1, 2009 |
|
# ? Jan 1, 2009 18:42 |
|
jstirrell posted:I have installed MySQL but the one module I can find that supposedly lets use work with MySQL doesn't seem to work with Python 2.6. I guess I could obviously downgrade the version I'm using, but I really have no idea if I'm even walking down the right path.
|
# ? Jan 1, 2009 23:25 |
|
Would using a dictionary work?
|
# ? Jan 2, 2009 18:29 |
|
It would, but you'd have to pickle and unpickle it all the time, but sqlite3 is perfect for this kind of stuff.
|
# ? Jan 2, 2009 18:41 |
|
Bonus posted:It would, but you'd have to pickle and unpickle it all the time, but sqlite3 is perfect for this kind of stuff. You wouldn't have to pickle if you didn't want to. Either way the stuff has to be entered and it could just be done in the python file. You wouldn't need to save answers to a separate file. If he didn't want everything in one file, the program and the answers together, he could have a separate python file for each book or chapter or whatever that has the questions and answers, makes a dictionary and whatever other functions he wants, and just import it from the main program. I'd just do it all in python instead of installing a database for it.
|
# ? Jan 2, 2009 20:39 |
|
chemosh6969 posted:You wouldn't have to pickle if you didn't want to. Sqlite3 is packaged by default with Python, and does not require an external database program. Scaevolus fucked around with this message at 20:56 on Jan 2, 2009 |
# ? Jan 2, 2009 20:52 |
|
Scaevolus posted:Writing the data into python files by hand is more painful than having a nice interface to input the pairs and then pickling or using a database. But is the data going to magic itself into a database or pickles? One could also write a prompt that asks for the input. Just saying. Side note: Does Sqlite3 work with mysql or is it it's own db?
|
# ? Jan 2, 2009 21:16 |
|
chemosh6969 posted:But is the data going to magic itself into a database or pickles? code:
quote:Side note: Does Sqlite3 work with mysql or is it it's own db? SQLite quote:SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain. Scaevolus fucked around with this message at 21:36 on Jan 2, 2009 |
# ? Jan 2, 2009 21:31 |
|
Basically sqlite is just a database stored within a single file and you can then run queries on that file and everything. Pretty much one of the best pieces of software around today.
|
# ? Jan 2, 2009 21:34 |
|
Bonus posted:Basically sqlite is just a database stored within a single file and you can then run queries on that file and everything. Pretty much one of the best pieces of software around today. Looks cool for small stuff.
|
# ? Jan 2, 2009 22:38 |
|
chemosh6969 posted:Looks cool for small stuff. Works surprisingly well for larger stuff too. SQLite owns.
|
# ? Jan 2, 2009 22:40 |
At what point does SQLite not scale well? I have a webspider that throws off some 40,000+ (small) entries per page. I'd like to use SQLite, but if it chokes on that many entries...
|
|
# ? Jan 2, 2009 23:32 |
|
Jo posted:At what point does SQLite not scale well? I have a webspider that throws off some 40,000+ (small) entries per page. I'd like to use SQLite, but if it chokes on that many entries... It wouldn't be too hard to write a quick little test to see if it scales the way you want it too...
|
# ? Jan 2, 2009 23:37 |
|
Why are you storing 40k entries per page?
|
# ? Jan 3, 2009 00:56 |
Bonus posted:Why are you storing 40k entries per page? Perceptual image hashing. 40k might be a bit of an exaggeration, as several entries will be discarded, but it's entirely possible for a single image to generate 30-3000 entries.
|
|
# ? Jan 3, 2009 03:14 |
|
I've been searching on google for a bit and I can't find any python methods or libraries for doing XML encoding. Does anything like that exist?
|
# ? Jan 3, 2009 09:31 |
|
tayl0r posted:I've been searching on google for a bit and I can't find any python methods or libraries for doing XML encoding. Well of course after I posted to this thread I found what I was looking for. http://docs.python.org/library/markup.html Edit: Hmm.. still trying to find something that *writes* XML Edit 2: ahh ha! http://docs.python.org/library/xml.sax.utils.html tayl0r fucked around with this message at 09:50 on Jan 3, 2009 |
# ? Jan 3, 2009 09:36 |
|
tayl0r posted:Well of course after I posted to this thread I found what I was looking for. http://docs.python.org/library/markup.html elementtree does writing as well
|
# ? Jan 3, 2009 18:37 |
|
jstirrell posted:Ok so I'm trying to write a program which basically allows me to input questions and their answers, organized by chapter/book/whatever so I can study them. My first Python program was pretty much this. I used it to learn German vocabulary. I stored everything in text files like so: english:german english:german A different text file for each topic and made a menu in Python to load whichever file I wanted. Then it would show a random English word and then after a keypress the corresponding German word.
|
# ? Jan 3, 2009 21:03 |
|
Hi, softball question here. Looking to learn Python this week. Would like a personal recommendation on what to work through. I may be working in a Python shop soon. I was contemplating working through some of the Euler challenges. I am slightly worried that might be a waste of time, and I don't want to focus too much on mathy things. I've worked with just about every other well-known programming language besides Python. From what I've seen I much prefer Python to Ruby, a language which leaves a bad taste in my mouth. Python seems to be designed by someone who understands powerful programming, whereas Ruby appears to be simply a mountain of syntax sugar. functional fucked around with this message at 20:26 on Jan 5, 2009 |
# ? Jan 5, 2009 20:17 |
|
The python tutorial is pretty good, and the euler problems are also pretty good to make sure you have the fundamentals sorted. A classic exercise is to re-write unix utilities like grep, wc, cat, tail, rev and sort in python.
|
# ? Jan 5, 2009 20:22 |
|
php:<? a=[0,1] for x in a: a.append(x) #infinite loop ?> php:<? a=[0,1] for x in range(len(a)): a.append(x) >>> a [0, 1, 0, 1] ?> Current guess: The for loop takes as its argument a pointer to a [mutable?] list. The list is evaluated only when the code enters the loop. Bounds checking and element retrieval is done at run time. functional fucked around with this message at 02:38 on Jan 6, 2009 |
# ? Jan 6, 2009 02:24 |
|
The expression after the 'in' is evaluated only once, and the result is then iterated over (via a call to __iter__, I believe, but that's not important here). This expression is NOT re-evaluated every time, AFAIK. In the first example, the expression evaluates to 'a', which is the name of a list object. Thus, the for loop iterates over "the object known as 'a'", and since that object keeps changing in the loop body, you get the infinite loop. In the second example, the expression evaluates to [0,1], because that's what range(len(a)) evaluates to when the loop is first entered. This is NOT a name of a list, but is instead just a list. The fact that it was initially generated based on the length of 'a' doesn't matter, because range(len(a)) was only called one time, in order to get the object-to-iterate-over. Thus, the second example works normally, because [0,1] never changes -- it's not tied to the value of 'a' in any way. Hope that made sense...it sounds like you sort-of figured it out in your guess, if I read you correctly.
|
# ? Jan 6, 2009 04:30 |
|
bitprophet posted:In the first example, the expression evaluates to 'a', which is the name of a list object. Thus, the for loop iterates over "the object known as 'a'", and since that object keeps changing in the loop body, you get the infinite loop. Not quite. The name is only evaluated once, but it's used to retrieve an iterator. Since the list is being expanded within the loop, the iterator will never run out of items. code:
|
# ? Jan 6, 2009 04:58 |
|
So just to be clear, it is perfectly fine in Python to mutate the collection being iterated over? Because in some languages (albeit, with some quirks), this is considered an error at either runtime or compile time. Is there any particular philosophical reason for Python to allow this, or is this more of a quirk rather than explicit language semantic?
|
# ? Jan 6, 2009 05:14 |
|
necrobobsledder posted:So just to be clear, it is perfectly fine in Python to mutate the collection being iterated over? Because in some languages (albeit, with some quirks), this is considered an error at either runtime or compile time. Is there any particular philosophical reason for Python to allow this, or is this more of a quirk rather than explicit language semantic? It's frowned upon, but particular semantics will depend on the type of the container being mutated. For example, mutating a dictionary will raise RuntimeError. I don't know if this behavior is documented anywhere except to say "don't do this".
|
# ? Jan 6, 2009 05:47 |
|
I seem to be getting a lot of memory not being cleared up after parsing XML using cElementTree.code:
If I run the same code (well, with: from lxml.etree import XML) using the lxml parser, I get all my space back. Is this a memory leak with cElementTree, or am I not understanding something? Also I would prefer not to even load the xml into memory, is there a good low memory way to read xml with python?
|
# ? Jan 6, 2009 17:33 |
|
I would highly recommend using lxml, I have found it a joy to use compared to elementtree http://codespeak.net/lxml/parsing.html quote:>>> tree = etree.parse("doc/test.xml")
|
# ? Jan 6, 2009 17:37 |
|
necrobobsledder posted:So just to be clear, it is perfectly fine in Python to mutate the collection being iterated over? Because in some languages (albeit, with some quirks), this is considered an error at either runtime or compile time. Is there any particular philosophical reason for Python to allow this, or is this more of a quirk rather than explicit language semantic? If you need to modify a list you're iterating over just slice the whole list: code:
|
# ? Jan 6, 2009 18:20 |
|
jstirrell posted:Ok so I'm trying to write a program which basically allows me to input questions and their answers, organized by chapter/book/whatever so I can study them. Alright I'm still working on this, the tips you guys gave me were great but I'm running into problems. I'm finding teaching myself to program to be extremely hard, especially since I don't really have anyone besides you guys in this thread to consult. When I read the tutorials, even doing typing out all the examples, I don't really feel I retain nearly as much knowledge as when I just take a simple seeming idea and try to program it, using google and the documentation mainly to tackle hurdles as they come up. So anyways, I'm currently just trying to to write code that can have questions inputted and sorted by subject and chapter, without worrying yet about having a hard copy saved somewhere for future use. Here's what I have so far: code:
Sorry for the wall of code, should I not be posting huge general questions here? I'm just kind of really lost. a cat fucked around with this message at 21:08 on Jan 6, 2009 |
# ? Jan 6, 2009 21:05 |
|
What does a tuple do that a list won't? Is it useful for anything? (You seem to be able to 'tuple pack' just fine with a list. Why would I switch over?)
functional fucked around with this message at 00:20 on Jan 7, 2009 |
# ? Jan 7, 2009 00:17 |
|
You can use a tuple as a hash key.
|
# ? Jan 7, 2009 00:27 |
|
functional posted:What does a tuple do that a list won't? Is it useful for anything? (You seem to be able to 'tuple pack' just fine with a list. Why would I switch over?) http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constant_lists/ Summary: Tuples are more like "records", and lists are "collections"
|
# ? Jan 7, 2009 00:28 |
|
Is there anything wrong with learning Python in 3.0 as opposed to 2.6?
|
# ? Jan 7, 2009 00:31 |
|
tef posted:You can use a tuple as a hash key. Five star answer. Thanks.
|
# ? Jan 7, 2009 00:33 |
|
|
# ? May 18, 2024 10:08 |
|
IntoTheNihil posted:Is there anything wrong with learning Python in 3.0 as opposed to 2.6? Yes, none of the libraries or third party things will support it yet. The leap to 3.0 from 2.6 isn't really that much - it's only to allow backwards incomatible changes. (Personally, at work, we're still using 2.5 at the moment). 3.0 isn't going to happen overnight, and I imagine most people won't switch until 3.1 at least - there are still changes that need to be refined, and the perfomance of 3.0 is slighly less than 2.6 at the moment. Learn the version of python you're most likely to encounter, but you can do future imports to bring most of the parts of 3.0 you want in.
|
# ? Jan 7, 2009 00:47 |