[Tutor] Iterating a dict with an iteration counter? How would *you* do it?

2013-02-04 Thread Modulok
in data.items(): print(i: %s, k: %s, v: %s % (i,k,v)) i += 1 Another variant, same idea:: data = {'a': apple, 'b': banana, 'c': cherry} for i,k,v in zip(range(len(data)), data.keys(), data.values()): print(i: %s, k: %s, v: %s % (i,k,v)) How would you do it? -Modulok

Re: [Tutor] Iterating a dict with an iteration counter? How would *you* do it?

2013-02-04 Thread Modulok
Hmm.. no kidding. Well, at least I knew I was over-complicating it. Cheers! -Modulok- On 2/4/13, Dave Angel da...@davea.name wrote: On 02/04/2013 12:13 PM, Modulok wrote: List, Simple question: Is there a common pattern for iterating a dict, but also providing access to an iteration

Re: [Tutor] optparse.OptionParser options in alphabetical order in help display

2012-12-18 Thread Modulok
. -Modulok- On 12/18/12, rail shafigulin rail.shafigu...@gmail.com wrote: Does anybody know if there is a way to make --help option to display options in alphabetical order? Right now it displays options in the order I added them. I'm using Python 3.1 Any help is appreciated. Thanks

Re: [Tutor] code to generate my own text captchas

2012-10-24 Thread Modulok
might look into writing a shell script or even python script wrapped around ImageMagick. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Passing arguments to running a python script on a remote machine from a python script on local machine .

2012-09-20 Thread Modulok
%s' % args Notice there are no longer quotes around each %s in cmd. Python 3.3 will have shlex.quote: http://docs.python.org/dev/library/shlex.html#shlex.quote Why is ``pipes.quote`` undocumented? It's useful. -Modulok- ___ Tutor maillist - Tutor

Re: [Tutor] [Semi-OT] Yes or no on using a Graphical IDE?

2012-09-15 Thread Modulok
others have more insight. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] Does anyone use UML?

2012-09-13 Thread Modulok
List, Does anyone use UML (Unified Modeling Language) with python? If so, what tools do you use? Is it worth the added effort? -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org

[Tutor] Genetic module recommendations?

2012-08-18 Thread Modulok
evolution. On the other hand, I don't want so much entropy that it's reduce to a random search. Before I write my own, I thought I'd ask to see if there was a third party, de-facto standard Python genetic module. Or at least one that is highly recommended. Any suggestions? Thanks! -Modulok

Re: [Tutor] specifying my default python installation

2012-08-17 Thread Modulok
...@freebsd.org ;) -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Confusion with Python, Bash and Command Prompt

2012-08-09 Thread Modulok
, assuming a correct shebang.) You are right in your assumption; It does not apply to Windows. The tutorial is incorrect. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo

Re: [Tutor] While learning Py: To IDE or not to IDE?

2012-05-20 Thread Modulok
-Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] TypeError: 'int' object is not callable

2012-05-16 Thread Modulok
' an integer. The easiest solution is to use another name for the variable 'factors' instead. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Is there space a between #! and /usr/bin/env python ?

2012-05-02 Thread Modulok
--ignore-case --regex '^#!/.*' --recursive /etc/rc* | wc On my FreeBSD server all files shipped with the OS don't uses spaces. They're just '#!/bin/sh'. However, some of my own scripts do, and they work regardless. i.e. It doesn't really matter. On Windows they're ignored entirely. -Modulok

Re: [Tutor] How to have the name of a function inside the code of this function?

2012-04-06 Thread Modulok
trying solve. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] breeds of Python .....

2012-03-31 Thread Modulok
: print foo #-- Now fails in 2.x print(foo)#-- Works. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Syntax error help

2012-03-30 Thread Modulok
'. Remember, python is case sEnsItiVe. e.g: Foo() and foo() are different. Good luck! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] tabbed output

2012-02-12 Thread Modulok
-Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python Database Scripting

2012-02-08 Thread Modulok
The closest thing you'll find will probably be the third party module 'sqlalchemy'. You can install it via easy_install or pip. If that doesn't meet your needs I'm not sure what else would. (But would love to hear about it.) -Modulok- On 2/8/12, Brad Hudson brad.hud...@gmail.com wrote: Can

Re: [Tutor] decimal precision in python

2012-02-06 Thread Modulok
For money, you should probably use the builtin module 'decimal' instead: http://docs.python.org/library/decimal.html There's also the third party module 'mpmath' which provides arbitrary precision floating point arithmetic. http://mpmath.googlecode.com/svn/trunk/doc/build/index.html -Modulok

Re: [Tutor] Error Checking/Defensive Programming

2012-01-25 Thread Modulok
that helps. -Modulok- On 1/25/12, Michael Lewis mjole...@gmail.com wrote: Hi everyone, I am new to python and have a noob question. Is it generally better to use try/except/else statements or if/elif/else? Or, is there a time and place for each? For a simple example, assume I want a user

Re: [Tutor] Simple Question (I Hope)

2012-01-14 Thread Modulok
On 1/14/12, Chris Kavanagh cka...@msn.com wrote: I was looking at this code from the Python Docs (http://docs.python.org/library/email-examples.html), trying to learn how to send email from a Pyhton script. Anyways, part of this code confused me. Here's the script: 1 # Import smtplib for the

Re: [Tutor] Your thoughts on designing python code for unit testing?

2012-01-04 Thread Modulok
a little different process, but that's how I do it. -Modulok- On 1/4/12, brian arb brianjames...@gmail.com wrote: What are some of the strategies for designing code to be unit tested? ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] sqlite3: turning on foreign key support thru python

2011-12-16 Thread Modulok
turned off:: (0,) Hope that helps. -Modulok- On 12/16/11, Monte Milanuk memila...@gmail.com wrote: I'm setting up an sqlite3 database to use as a base for some programming stuff I want to work on. Currently using python 2.7, which appears to have a new enough version of sqlite (just

Re: [Tutor] where python is used in real world

2011-12-04 Thread Modulok
2. If one wants to make a commercial software using python, how can he hide the code? While it's a valid question, it's fun to imagine it in the physical world: We need to permanently weld the engine compartment closed so that no one can steal our engine ideas. -Modulok

Re: [Tutor] File vs. Database (possible off topic)

2011-11-21 Thread Modulok
, mysql and a few others. It's a good idea to get used to sqlite and general SQL concepts before you jump into sqlalchemy! Good luck! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org

Re: [Tutor] methods vs. functions

2011-08-22 Thread Modulok
On 8/22/11, Prasad, Ramit ramit.pra...@jpmorgan.com wrote: Steven D'Aprano wrote: (Methods are very similar to functions. At the most basic level, we can pretend that a method is just a function that comes stuck to something else. Don't worry about methods for now.) Can someone please explain

Re: [Tutor] floats

2011-06-06 Thread Modulok
Can someone till me how to get a two decimal precision every time? print %.2f % (500/1000.0) # or... result = 500 / 1000.0 print %.2f % result Using 'new' style string formatting works too: print {0:.2f}.format(500/1000.0) -Modulok- On 6/6/11, Michael bridges micha_el2

Re: [Tutor] Clunky Password maker

2011-05-25 Thread Modulok
+ string.punctuation passwd = for i in range(passlen): passwd += r.choice(chars) print passwd -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Titles from a web page

2011-05-04 Thread Modulok
You might look into the third party module, 'BeautifulSoup'. It's designed to help you interrogate markup (even poor markup), extracting nuggets of data based on various criteria. -Modulok- On 5/4/11, louis leichtnam l.leicht...@gmail.com wrote: Hello Everyone, I'm trying to write a program

Re: [Tutor] How to solve this problem in python?

2011-04-24 Thread Modulok
.) -Modulok- On 4/24/11, Ratna Banjara mast.ra...@gmail.com wrote: Write a function named countRepresentations that returns the number of ways that an amount of money in rupees can be represented as rupee notes. For this problem we only use rupee notes in denominations of 1, 2, 5, 10 and 20

Re: [Tutor] Metaclass confusion...

2011-04-20 Thread Modulok
and broadened my understanding :) Excellent examples as well. Love the class name too. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] Metaclass confusion...

2011-04-19 Thread Modulok
-- I could add the attribute in the definition or a decorator, but the point was learning to use (albeit abuse) metaclasses. Anyway, if anyone could take a look I'd be grateful. Thanks! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe

Re: [Tutor] String formatting question.

2011-03-29 Thread Modulok
For simple strings I use the %s % foo version, for more complex stuff I use the .format() method. I find it easier to control spacing and alignments with the .format() method, but that's just me. -Modulok- On 3/29/11, Blockheads Oi Oi breamore...@yahoo.co.uk wrote: On 29/03/2011 20:41, Prasad

Re: [Tutor] time taken to execute certain task

2011-03-17 Thread Modulok
'timeit' if you're trying to benchmark things. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] Shared web host and setting the python environment...

2011-03-04 Thread Modulok
company or a virtual private server.) Any suggestions appreciated. Thanks! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Help - want to display a number with two decimal places

2011-03-04 Thread Modulok
a precision of 2 decimal places, '.2'. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] File transfer HTTP - SFTP

2011-03-01 Thread Modulok
command with python via the subprocess module if needed. -Modulok- On 3/1/11, Emanuel Lauria emanuel.lau...@gmail.com wrote: Sorry if im annoying, but I think this is a better question than my previous one of today. I have some Images in an HTTP Server that I need to transfer to an SFTP server

[Tutor] Generator expressions...

2011-02-27 Thread Modulok
something obvious. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Generator expressions...

2011-02-27 Thread Modulok
the generator expression. What are you iterating over? How long is the string returned by the read? I knew it was subtle. I was trying to use 'read(4096)' like open()'s buffersize parameter. (Which it's obviously isn't.) Thanks! -Modulok- ___ Tutor

Re: [Tutor] accessing another system's environment

2011-02-26 Thread Modulok
I'm coming into this thread late so I might be off the mark here, but it seems like you're going about it backwards: Instead of trying to reach in and modify a user's environment, which is highly variable and process dependent, why not just wrap the software they're running? Have a python script

Re: [Tutor] accessing another system's environment

2011-02-26 Thread Modulok
On 2/26/11, Modulok modu...@gmail.com wrote: ... The server then replies with any variables that the client needs to set and their values. You could do this with a python script running on a server sending ajax responses. (There's an ajax module in the standard library.) ... Sorry, I meant

Re: [Tutor] Try except really better than if?

2011-01-09 Thread Modulok
it with an if statement first. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] Weighted Random Choice - Anyone have an efficient algorithm?

2010-12-22 Thread Modulok
)) return flattened[rnd] # Not test it: print wrandom([5, 20, 75]) print wrandom([5, 20, 75]) print wrandom([5, 20, 75]) ### End Code Example ### It works and is easy enough to understand, but when the number of list items gets large, or the weights get heavy, things get ugly. -Modulok

[Tutor] unit testing - Separate methods or group tests together?

2010-12-17 Thread Modulok
List, When you create unit tests, do you group tests for a given function together into one unit test method, or do you prefer to have separate test methods for every assert statement? Thanks! -Modulok- ___ Tutor maillist - Tutor@python.org

Re: [Tutor] Writing to the terminal?

2010-12-12 Thread Modulok
List, Thanks! I think I got it working now with the help of some suggestions :-) For more complex stuff, (think blue screens with little white boxes you press spacebar to activate. Kind of like an OS installer) I would look into the `curses` module in the standard library? Thanks! -Modulok

[Tutor] Writing to the terminal?

2010-12-10 Thread Modulok
. (If that makes any sense?) Think of console based progress counters in programs like fetch or wget, or lame. How do you do this in Python? -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org

Re: [Tutor] Calling Program within Program

2010-12-09 Thread Modulok
Patty, I didn't read through your code, but to call an external program see the 'subprocess' module in the standard library: http://docs.python.org/library/subprocess.html -Modulok- On 12/9/10, pa...@cruzio.com pa...@cruzio.com wrote: Hello: I would like to know how to call a program from

Re: [Tutor] True Random Numbers

2010-11-03 Thread Modulok
using the random numbers for? -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] unittest testing order...

2010-09-27 Thread Modulok
List, When using the unittest module, tests are run in alphanumeric order. What's the suggested way of specifying a test order? Any code examples would be great! Thanks -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] unittest testing order...

2010-09-27 Thread Modulok
On 9/27/10, Steven D'Aprano st...@pearwood.info wrote: On Tue, 28 Sep 2010 04:03:17 am Modulok wrote: List, When using the unittest module, tests are run in alphanumeric order. What's the suggested way of specifying a test order? There isn't one. It shouldn't matter what order the tests run

Re: [Tutor] quick speed question

2010-09-16 Thread Modulok
97% of the time: premature optimization is the root of all evil -Donald knuth- -Modulok- On 9/16/10, C.T. Matsumoto c.t.matsum...@gmail.com wrote: Hello Tutors, I was just wondering if you have a dictionary key is it faster to do: if dict['key'] == 'foo': ... or is this faster

Re: [Tutor] Advice on math

2010-06-27 Thread Modulok
the forum thread, do you realize how crude your own solutions are, compared to some very clever fellows. Far better than a crossword to keep things stimulated. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options

[Tutor] Data exchange formats...

2010-06-20 Thread Modulok
List, What's the best format to send data across the wire between processes? I have some simple 'insensitive' data I need to send from a client, to a server via a TCP socket. Things like 'count = 10, name=foo' and so forth. Basic values. I would use something like the 'pickle' module to pack

Re: [Tutor] help

2010-06-17 Thread Modulok
Solution: width times height. On 6/17/10, KB SU k24...@gmail.com wrote: help ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] Trouble with sockets...

2010-06-17 Thread Modulok
List, I'm new to sockets and having trouble. I tried to write a simple client/server program (see code below). The client would send a string to the server. The server would echo that back to the client. PROBLEM: I can send data to the server, and get data back, but only for the first call to

Re: [Tutor] Making pretty web pages from python code examples?

2010-04-14 Thread Modulok
the docstrings from your python modules. Much easier than building your own. Thanks! Looks like just what I'm after. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] Making pretty web pages from python code examples?

2010-04-13 Thread Modulok
the files was a rut. Thanks. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Introduction to modelling with Python

2010-03-28 Thread Modulok
interface to automate things. See the developer's documentation for whatever software you're using. What kind of modeling? -Modulok- On 3/27/10, AG computing.acco...@googlemail.com wrote: Hi List I apologise in advance for the vagueness of this query, but I am looking for a decent modern

Re: [Tutor] Bowing out

2010-03-03 Thread Modulok
and answers. I learned a lot from my participation here. Kent, I'm a relative newcomer, but even so, I benefited from you. Thanks for giving what you could! Best of luck with your new endeavors. Hope to see you check back in from time to time. -Modulok

Re: [Tutor] Encryption

2010-02-22 Thread Modulok
implementations out there as well. However, the only FIPS certified library I know of is openssl. -Modulok- On 2/22/10, Shashwat Anand anand.shash...@gmail.com wrote: how about using base64? base64.encodestring(s) will do. On Tue, Feb 23, 2010 at 2:30 AM, Wayne Werner waynejwer

Re: [Tutor] adding more text to a file

2010-01-18 Thread Modulok
(name, age)) # We'll never get this far unless we figure out a way to stop the loop! out_file.close() Keep at it and best of luck! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org

[Tutor] How to create memory backed file?

2009-12-27 Thread Modulok
: fileno I'm using Python 2.5, so I cannot use that slick 'SpooledTemporaryFile' method of the 'tempfile' module. The 'cat' is just a simple Unix system command for the purpose of illustration. Thanks! -Modulok- ___ Tutor maillist - Tutor@python.org

Re: [Tutor] How to create memory backed file?

2009-12-27 Thread Modulok
Kent, Thanks! I think that'll do it. I don't know what this list would do without you! -Modulok- On 12/27/09, Kent Johnson ken...@tds.net wrote: On Sun, Dec 27, 2009 at 3:36 AM, Modulok modu...@gmail.com wrote: List, How do I create a file which exists only in memory? (Think diskless.) I

Re: [Tutor] More on unit testing - tests for external data...

2009-12-10 Thread Modulok
? Thanks! -Modulok- On 12/10/09, spir denis.s...@free.fr wrote: Wayne Werner waynejwer...@gmail.com dixit: On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld alan.ga...@btinternet.comwrote: Remember, in testing you are not trying to prove it works but rather to demonstrate that it doesn't

[Tutor] More on unit testing - tests for external data...

2009-12-09 Thread Modulok
? If anyone could point to a few examples of such usage, that would be great! Thanks! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] python time

2009-11-27 Thread Modulok
. time.time() 1259288538.576565 Right? -Modulok- For sure, but this wasn't my question. I was precisely asking how python does that. Clearly I have a mighty need to consume more coffee. My apologies for misreading the original post. -Modulok

Re: [Tutor] python time

2009-11-26 Thread Modulok
. time.time() 1259288538.576565 Right? -Modulok- On 11/26/09, Kent Johnson ken...@tds.net wrote: On Wed, Nov 25, 2009 at 11:11 AM, spir denis.s...@free.fr wrote: Hello, How does python get the time in microseconds? (In other words, how would I get it if python (like some other languages) would

Re: [Tutor] Fwd: Help on finding the 1000th prime

2009-11-16 Thread Modulok
Also watch things like letter case on stuff like 'Print' and 'While', they should instead be 'print' and 'while', (all lowercase). -Modulok- On 11/16/09, bob gailer bgai...@gmail.com wrote: Here is the code that doesn't work. Thanks for posting the code. What doesn't work mean? error

[Tutor] OT: Writing code while tired, counterproductive?

2009-11-14 Thread Modulok
wondering if this is a common occurrence among the masses. Anyone? -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to call a method with a print statement?

2009-11-13 Thread Modulok
List, __repr__() is exactly what I was looking for :) You guys rock! Thank you. -Modulok- On 11/12/09, Dave Angel da...@ieee.org wrote: Kent Johnson wrote: On Thu, Nov 12, 2009 at 6:35 AM, Luke Paireepinart rabidpoob...@gmail.com wrote: On Thu, Nov 12, 2009 at 5:29 AM, Jeff R. Allen j

[Tutor] How to call a method with a print statement?

2009-11-12 Thread Modulok
! # Now use it: bar = Foo() print bar hello world! #-- Magic! If any of this makes sense, any pointers would be great! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo

Re: [Tutor] Evaluating a string expression

2009-11-05 Thread Modulok
in the example URL provided by one of the other responses. (http://effbot.org/zone/librarybook-core-eval.htm) Sorry for all the lecture. I'll shut up now. :p -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http

Re: [Tutor] why is os.path.walk so slow?

2009-11-04 Thread Modulok
short, and it may not even be applicable, but have you looked into rsync? They kind of wrote the book on efficiency in regards to synchronization of files. Just a thought. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] Stolen thread: Bottom folk vs. toppers was trouble using 2to3.py

2009-11-03 Thread Modulok
that the only requirement to communications here is that replies and questions be well formulated, courteous, and reasonably intelligent. Yup. -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org

Re: [Tutor] Generating unique ID

2009-10-29 Thread Modulok
If it absolutely must be unique, use a database manager that can make that guarantee. Best of luck! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to load a dict into a dict subclass?

2009-10-28 Thread Modulok
() myvar.update(foo) myvar {'a': 100, 'c': 300, 'b': 200} ... /snip Thanks guys! Christian, that's just what I was looking for. Thank you! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http

[Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread Modulok
in foo.items(): myvar[k] = v ### END CODE Obviously I can put the dict into an instance variable, but then methods like 'keys()' and such won't work. If that makes any sense... Thanks guys! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubscribe