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
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
.
-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
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
%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
others have more insight.
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
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
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
...@freebsd.org ;)
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
, 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
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
' 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
--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
trying solve.
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
:
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
'.
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
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
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
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
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
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
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
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
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
, 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
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
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
+ 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
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
.)
-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
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
--
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
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
'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
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
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
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
something obvious.
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
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
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
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
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
))
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
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
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
. (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
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
using the random numbers for?
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
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
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
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
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
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
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
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
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
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
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
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
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
(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
: 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
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
?
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
? 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
.
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
.
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
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
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
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
!
# 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
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
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
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
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
()
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
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
77 matches
Mail list logo