Hmm.. no kidding. Well, at least I knew I was over-complicating it.
Cheers!
-Modulok-
On 2/4/13, Dave Angel 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 acc
t;}
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-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
s probably the
best place to check it out.
-Modulok-
On 12/18/12, rail shafigulin 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 usi
ou 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
)
> cmd = 'python test.py %s %s %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-
ls like ipython can make up for
some of that, but even so that's not something I generally write code in.
Perhaps 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
to the point of haulting 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
recommen
python with the version you choose, but it will work.
Finally, if you want to get carried away, you can install a virtual python as
mentioned.
For even more options, you might subscribe to questi...@freebsd.org ;)
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
der reading shebang lines. The file
would be passed to the python interpretter, 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 unsubscri
lable. You can also ooze right into system administration without much
effort.
But again, that's just me :p
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
he call to the function 'factors'. You get the error because you
assigned factors an integer and you cannot 'call' 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
cursive /etc/rc* | wc
And this respectively::
grep --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
ame_info.function)
foo()
That said, there's probably a better way to solve whatever bigger problem
you're trying solve.
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
division
Now in 2.x, just like 3.x this will raise an exception:
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
s well:
print ' the side length is' sidelength ** 2
The print statement only takes a single argument, or multiple arguments *if*
they are comma separated, e.g:
print ' the side length is', sidelength ** 2
However, this whole thing would be better written using string substitution::
print ' the side length is %s' % (sidelength ** 2)
This is also incorrect:
Areamenu()
Your code defines a function named 'areamenu', not one named 'Areamenu'.
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
ment),
As a final note, if 'CheckNames' is a function and not a method, it should be
all lowercase, or use_underscores rather than camelCase. This is not enforced
by python, but is kind of the de-facto standard.
Read more about the format method here:
http://docs.python.org/library/string.html#formatspec
http://docs.python.org/library/string.html#formatstrings
-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 wro
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/b
print("You loose!")
The rule doesn't always hold true, but it's a general guideline.
Hope that helps.
-Modulok-
On 1/25/12, Michael Lewis wrote:
> Hi everyone,
>
> I am new to python and have a noob question.
>
> Is it generally better to use try/except/else
On 1/14/12, Chris Kavanagh 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 actual s
you can.
Everyone has a little different process, but that's how I do it.
-Modulok-
On 1/4/12, brian arb wrote:
> What are some of the strategies for designing code to be unit tested?
>
___
Tutor maillist - Tutor@python.org
To unsubscribe
thing like this when foreign keys are turned on::
(1,)
Or this when they're turned off::
(0,)
Hope that helps.
-Modulok-
On 12/16/11, Monte Milanuk wrote:
> I'm setting up an sqlite3 database to use as a base for some programming
> stuff I
> want to work on. Currently
>> 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
o
s for you. The most popular module is probably
sqlalchemy. It talks to postgresql, 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 -
On 8/22/11, Prasad, Ramit 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 the difference bet
>> 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/
passwd[3]
> print ""
> print "".join(map(str, passwd)), " is your new password. \n"
> [/code]
>
> [output]
>>>>
> Enter 1 to run a MD5hash on your password
> Enter 2 to run a SHA1 hash on your password
> Ente
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 wrote:
> Hello Everyone,
>
> I'm trying to wr
t; generally doesn't.)
-Modulok-
On 4/24/11, Ratna Banjara 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 o
nk you! You've solved my problem 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
r(Foo, 'serial')#<-- I was really expecting this to be True.
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-
__
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 wrote:
> On 29/03/2011 20:41, Prasad,
psed = ", end - start, "seconds"
>
> thanks
> tcl
>
Also look into the builtin module '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
hase Price", purchasePrice)
# First prints the first argument (the 0th index) to 'format(),
# left aligned '<', and 18 characters wide, whitespace padded.
# Then prints the second argument, (the 1st index) right aligned,
# also 18 characters wide, but the second argument is specified to
# be a float 'f', that has 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
complish this? (Aside
from a new hosting 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
he above command with python via the subprocess module
if needed.
-Modulok-
On 3/1/11, Emanuel Lauria 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
>
. Why?
>>
>> except KeyboardInterrupt:
>>gen.close()
>>fd.close()
>>print "\nBye!"
>>
> Check out the generator expression. What are you iterating over? How
> long is the string returned by the read?
I knew it was s
ose()
print "\nBye!"
## End code
I've got to be missing something obvious.
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
On 2/26/11, Modulok 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 mean
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 w
and use an
exception as accident insurance. If it will usually fail, check 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
.append(i)
if debug: print "flattened: ", flattened
rnd = random.randint(0, (len(flattened) - 1))
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
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
To
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
evious
number... I just want to change it in place. (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
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 wrote:
>
> Hello:
>
> I would like to know how to c
random
foo = random.SystemRandom() # Uses /dev/urandom or Windows CryptGenRandom
# Print 10 random numbers:
for i in range(10):
foo.random()
What are you using the random numbers for?
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
On 9/27/10, Steven D'Aprano 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.
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 c
at it. (This list is great for that!) If that too
fails, start think about writing a few critical bits in C, but only as
a last resort.
"We should forget about small efficiencies, say about 97% of the time:
premature optimization is the root of all evil" -Donald knuth-
-Modulok-
On 9
ou have basic understanding of
> maths.
Not to hijack the thread, but that's awesome! Only when you solve the
problems and then read 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.
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 th
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
Solution: width times height.
On 6/17/10, KB SU wrote:
> help
>
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
es/features for pulling 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://m
parse 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
a command 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 wrote:
> Hi List
>
> I apologise in advance for the vagueness of this query, but I am looking
> for a decent modern introd
ne who contributes questions 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
f pycrypto. There are probably other AES implementations out
there as well. However, the only FIPS certified library I know of is
openssl.
-Modulok-
On 2/22/10, Shashwat Anand wrote:
> how about using base64? base64.encodestring(s) will do.
>
>
>
> On Tue, Feb 23, 2010 at 2:30 AM, Wa
ame: ")
age = raw_input("What is the age: ")
out_file.write("name:%s\nage: %s\n\n" (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-
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 wrote:
> On Sun, Dec 27, 2009 at 3:36 AM, Modulok wrote:
>> List,
>>
>> How do I create a file which exists only in memory? (Think diskless
error:
Traceback (most recent call last):
File "", line 1, in
AttributeError: 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 c
t's
been frustrating as hell.
Case studies/tutorials anyone?
Thanks!
-Modulok-
On 12/10/09, spir wrote:
> Wayne Werner dixit:
>
>> On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld
>> wrote:
>>
>> >
>> > Remember, in testing you are not trying to prove
y? 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
urrent time in seconds since the Epoch.
>> Fractions of a second may be present if the system clock provides
>> them.
>>
>>
>> >>> time.time()
>> 1259288538.576565
>>
>> Right?
>> -Modulok-
>
> For sure, but this wasn't
system clock provides them.
>>> time.time()
1259288538.576565
Right?
-Modulok-
On 11/26/09, Kent Johnson wrote:
> On Wed, Nov 25, 2009 at 11:11 AM, spir wrote:
>> Hello,
>>
>> How does python get the time in microseconds? (In other words, how would I
>> get
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 wrote:
>
>> Here is the code that doesn't work.
>>
>
> Thank
different angles on the matter, from the
Python community.
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
ines. *grumble*
Just 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 wrote:
>
>
> Kent Johnson wrote:
>> On Thu, Nov 12, 2009 at 6:35 AM, Luke Paireepinart
>> wrote:
>>
>>> On Thu, Nov 12, 2009 at 5:29 AM, Je
nt "hello world!"
# 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:
ht
. But in most
situations executing code from an untrusted source is a *really* bad
idea, even with precautions as those outlined 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
-Modulo
o cut your coding project 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 unsu
imply propose 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 su
be
unique. It's just, "probably unique". It would look like this:
>>> import time
>>> time.time()
1256796357.661967
If it absolutely must be unique, use a database manager that can make
that guarantee.
Best of luck!
-Modulok-
gt; ### END CODE
>>
> You can use the built-in function for dictionaries called update. So
>
> >>> class Bar(dict):
> >>> pass
>
> >>> foo = {'a':100, 'b':200, 'c': 300}
> >>> myvar = Bar()
>
rn value.
myvar = Bar()
# The hacky feeling part:
for k,v 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-
___
78 matches
Mail list logo