Re: Why has python3 been created as a seperate language where there is still python2.7 ?

2012-06-25 Thread Michiel Overtoom

On Jun 24, 2012, at 05:46, gmspro wrote:

> Why has python3 been created as a seperate language where there is still 
> python2.7?

It has not. Python2 and Python3 are very similar. It's not like if you learn 
Python using version 2, you have to relearn the language when you want to 
switch Python3.  The syntax is the same, only 'print' is a function instead of 
a statement. Other improvements are unicode strings, cleanups in the library, 
lazy iterators, new-style classes by default etc... mostly background stuff you 
won't even notice in daily Python use.

Greetings,

-- 
Test your knowledge of flowers! http://www.learn-the-flowers.com
or http://www.leer-de-bloemen.nl for the Dutch version.

Test je kennis van bloemen! http://www.leer-de-bloemen.nl
of http://www.learn-the-flowers.com voor de Engelse versie.




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for video/slides from PyCon 2011...

2012-05-21 Thread Michiel Overtoom

On May 16, 2012, at 08:24, Monte Milanuk wrote:
>>> 
>>> http://us.pycon.org/2011/schedule/presentations/207/
> 
> Unless its buried in one of the lightning talk vids, I'm not seein' it.


Me neither. But that page show that it was a workshop, not necessarily 
videotaped. That's a pity, it seems interesting to me.

Greetings,

-- 
Test your knowledge of flowers! http://www.learn-the-flowers.com
or http://www.leer-de-bloemen.nl for the Dutch version.

Test je kennis van bloemen! http://www.leer-de-bloemen.nl
of http://www.learn-the-flowers.com voor de Engelse versie.




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regarding session in python

2011-06-07 Thread Michiel Overtoom

On Jun 7, 2011, at 20:09, Kev Dwyer wrote:

> vipul jain wrote:
> 
>> hey i am new to python and i want to make a website using python .
>> so for that i need a login page. in this login page i want to use the
>> sessions... but i am not getting how to do it
> 
> The Python standard library doesn't include a session framework, but you 
> can either use a web framework written in Python (Django is the most 
> popular).

"Django comes with a user authentication system. It handles user accounts, 
groups, permissions and cookie-based user sessions. This document explains how 
things work."

https://docs.djangoproject.com/en/dev/topics/auth/

Greetings,

-- 
"Learn to value yourself, which means: fight for your happiness."  - Ayn Rand   
   

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SQL Server 2008R2 databases via Python 2.7 and Windows XP and higher

2011-06-17 Thread Michiel Overtoom

On Jun 17, 2011, at 17:01, pyt...@bdurham.com wrote:

> Looking for some real-world advice on what is the best way to access MS SQL 
> Server 2008R2 databases via Python 2.7 running under Windows XP, Vista, and 
> Windows 7 and Windows Server 2005 and 2008.

I use the COM interface to ADO, for a few years already, but want to rewrite my 
scripts to the standard DBAPI 2.0 sometime to be less dependent on Windows. 

-- 
"Freedom: To ask nothing. To expect nothing. To depend on nothing." - Ayn Rand

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-22 Thread Michiel Overtoom

On Jul 22, 2011, at 12:23, Thomas Jollans wrote:

> On 22/07/11 10:11, Thomas Rachel wrote:
>> Am 22.07.2011 00:45 schrieb Terry Reedy:
>> 
>>> Whether or not they are intended, the rationale is that lining up does
>>> not work with proportional fonts.
>> 
>> Who on earth would use proportional fonts in programming?!
> 
> Why not?

Indeed. Since Windows95 I always use a proportional font for programming:

  http://www.michielovertoom.com/incoming/comic-sans-python.jpg

It's so elegant and gives aesthetic pleasure to look at.

Greetings,

-- 
"If you don't know, the thing to do is not to get scared, but to learn." - Ayn 
Rand  



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Announcing a new podcast: Radio Free Python

2011-08-24 Thread Michiel Overtoom

On Aug 24, 2011, at 06:15, Larry Hastings wrote:

> Radio Free Python is a new monthly podcast focused on Python and its 
> community.

Excellent initiative!  I love to listen to podcasts about Open Source software 
and Python, on my MP3 player, while I take long walks in the countryside.

I hope you'll have the same stamina as FLOSS Weekly 
(http://en.wikipedia.org/wiki/Floss_weekly). In the past years there have been 
some Python podcast initiatives, but most of them didn't last very long.  I 
guess it takes a substantial amount of energy and commitment to produce regular 
podcasts over a long period of time.  Do you need any input/ideas/feedback ?

Greetings,
Michiel Overtoom
http://www.michielovertoom.com

-- 
"Learn to value yourself, which means: fight for your happiness."  - Ayn Rand   
   

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unspecified problem sending serial data

2011-08-24 Thread Michiel Overtoom

On Aug 24, 2011, at 23:51, Dave Angel wrote:

> On 08/24/2011 01:05 PM, Adrián Monkas wrote:
>> What I want to do is send around 180KBytes via Serial port.

Also have a look at pySerial, http://pyserial.sourceforge.net/

Greetings,

-- 
"If you don't know, the thing to do is not to get scared, but to learn." - Ayn 
Rand  



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Constructors...BIIIIG PROBLEM!

2011-09-01 Thread Michiel Overtoom

On Sep 1, 2011, at 09:48, Amogh M S wrote:

> Hey guys... 
> I think we have a problem with my _init_ method and the constructor
> When I create a class and its _init_ method and try to create an object of it 
> outside the class,
> Say, something like
> 
> class S:
>def _init_(self, name=None):
>self.name = name
> s = S("MyName")

Two things: Derive your class from object, and the constructor function should 
be '__init__', that is, with *two* underscores before and after it. Are you 
reading a book or tutorial which does use a badly chosen font which doesn't 
distinguish two consecutive underscores well?

class S(object):
def __init__(self, name=None):
self.name = name

s = S("MyName")
print s.name

Greetings,


-- 
"If you don't know, the thing to do is not to get scared, but to learn." - Ayn 
Rand  



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Constructors...BIIIIG PROBLEM!

2011-09-01 Thread Michiel Overtoom

On Sep 1, 2011, at 10:24, Hegedüs Ervin wrote:

> On Thu, Sep 01, 2011 at 10:00:27AM +0200, Michiel Overtoom wrote:
>> Derive your class from object,
> 
> why's that better than just create a simple class, without
> derive?

Amongst other things, fixes to the type system and the method resolution order.

http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes
http://unspecified.wordpress.com/2010/11/18/pythons-new-classes-vs-old-classes/
http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html
http://www.python.org/download/releases/2.2.3/descrintro/

Greetings,

-- 
"If you don't know, the thing to do is not to get scared, but to learn." - Ayn 
Rand  



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do class methods always need 'self' as the first parameter?

2011-09-01 Thread Michiel Overtoom

> On Aug 31, 5:35 pm, "T. Goodchild"  wrote:


>> So why is 'self' necessary on class methods?
>> 
>> Just curious about the rationale behind this part of the language.

When instance variables are accessed with the 'self.varname' syntax, it is 
clear to the programmer that an instance variable is accessed, and not some 
global.  Other languages have weird syntax conventions like that you have to 
prepend all instance attributes with an '@', and in languages like C++ where 
there is not necessarily such a syntactic requirement, many programmers use 
ad-hoc constructs like '_varname' or 'm_varname' to make the distinction clear.


>> It seems to me that the
>> most common practice is that class methods *almost always* operate on
>> the instance that called them.  It would make more sense to me if this
>> was assumed by default, and for "static" methods (methods that are
>> part of a class, but never associated with a specific instance) to be
>> labelled instead.

Yes, you have a point there. My personal preference would be to optimize for 
the most common case, while exceptions to the norm are still possible, but 
perhaps a bit more verbose.

Greetings

-- 
"Learn to value yourself, which means: fight for your happiness."  - Ayn Rand   
   

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to extract sentence from txt file

2011-05-17 Thread Michiel Overtoom

On May 17, 2011, at 20:22, Robert Pazur wrote:

> my question is maybe quite simple:
> What is the best (and shortest) way to extract sentence from .txt file?

Well, open("filename.txt").readlines() gives you a list of all the lines in a 
txt file, which might not be sentences, depending on the text file is 
structured.  If you really want to interpret the text file as a collection of 
sentences, some parsing might be involved. What is a sentence? A sequence of 
words ending with a dot? With a question mark? How do quotes play a role in 
this?

Did you have a specific sentence (or line) in thought? The first line? The last 
line? A random line somewhere in between?

Until then we have to guess, and my E.S.P. is notoriously bad.

Greetings,

-- 
"Learn to value yourself, which means: fight for your happiness."  - Ayn Rand   
   

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why searching in a set is much faster than in a list ?

2016-09-28 Thread Michiel Overtoom
Hi,

Brandon Rhodes gave a talk about dictionaries (similar to sets), 'The Mighty 
Dictionary': 

https://www.youtube.com/watch?v=C4Kc8xzcA68


You also might be interested in his talk about Python data structures, 'All 
Your Ducks In A Row':

https://www.youtube.com/watch?v=fYlnfvKVDoM

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to you convert list of tuples to string

2016-11-22 Thread Michiel Overtoom
Hi Ganesh,

> Any better suggestion to improve this piece of code and make it look more 
> pythonic?


import random

# A list of tuples. Note that the L behind a number means that the number is a 
'long'.

data = [(1, 1, 373891072L, 8192), (1, 3, 390348800L, 8192), (1, 4, 372719616L,
8192), (2, 3, 382140416L, 8192), (2, 5, 398721024L, 8192), (3, 1,
374030336L, 8192), (3, 3, 374079488L, 8192), (3, 5, 340058112L, 8192)]

item = random.choice(data)  # Select a random item from the 'data' list.

msg = "%d,%d,%d:%d" % item  # Format it in the way you like.

print msg


Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Parse a Wireshark pcap file

2016-12-28 Thread Michiel Overtoom

> On 2016-12-27, at 20:46, 1991manish.ku...@gmail.com wrote:
> 
> I have a pcap file, I want to parse that file & fetch some information like 
> Timestamp, Packet Size, Source/Dest IP Address, Source/Dest Port, Source/ 
> Dest MAC address.

pcapy can do this.

import pcapy
pcap = pcapy.open_offline("httpsession.pcap")

def callback(hdr, data):
... do something with hdr and data, which is the captured packet

pcap.loop(0, callback)

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using sudo with pip3?

2017-01-07 Thread Michiel Overtoom

> On 2017-01-07, at 03:24, Cameron Simpson  wrote:
> 
> Having your on virtualenv is good for: [...] having an isolated environment 
> for packages (you can make more than one virtual environment).

Yes, indeed. For example, if you have to maintain two different codebases, one 
using Django 1.8 and the other Django 1.10 and a slew of other packages, for 
example an older and newer version of allauth, you'd have to create two virtual 
environments or otherwise you'll end up with a broken situation.

Greetings,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: def __init__(self,cls):

2016-04-29 Thread Michiel Overtoom

> On 2016-04-29, at 11:47, San  wrote:
> 
> Dear Group, please explain the following in details. Thanks in Advance.
> 
> def __init__(self,cls):
>self.cls = cls

Is this homework? Why don't you explain it first in your own words, then let us 
comment on it?

Greetings,



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I count word frequency in a web site?

2015-11-29 Thread Michiel Overtoom

> On 30 Nov 2015, at 03:54, ryguy7272  wrote:
> 
> Now, how can I count specific words like 'fraud' and 'lawsuit'?

- convert the page to plain text
- remove any interpunction
- split into words
- see what words occur
- enumerate all the words and increase a counter for each word

Something like this:

s = """Today we're rounding out our planetary tour with ice giants Uranus
and Neptune. Both have small rocky cores, thick mantles of ammonia, water,
and methane, and atmospheres that make them look greenish and blue. Uranus
has a truly weird rotation and relatively dull weather, while Neptune has
clouds and storms whipped by tremendous winds. Both have rings and moons,
with Neptune's Triton probably being a captured iceball that has active
geology."""

import collections
cleaned = s.lower().replace("\n", " ").replace(".", "").replace(",", 
"").replace("'", " ")
count = collections.Counter(cleaned.split(" "))
for interesting in ("neptune", "and"):
print "The word '%s' occurs %d times" % (interesting, count[interesting])


# Outputs:

The word 'neptune' occurs 3 times
The word 'and' occurs 7 times




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python domain in China. This showed up on Python list

2015-12-01 Thread Michiel Overtoom

Hi,

> On 01 Dec 2015, at 11:10, Laura Creighton  wrote:
> 
> I think we have just dodged a bullet, let us now go thank the
> nice people who sent us this and figure out how we should
> secure the domain.

I received exactly the same email a while ago, claiming that someone was 
registering the name 'Michiel' in China as 'internet keyword' (whatever that 
may be), and whether I knew them. I responded 'no', and have never since heard 
from them.

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How does one distribute Tkinter or Qt GUI apps Developed in Python

2015-12-17 Thread Michiel Overtoom

> On 2015-12-17, at 01:03, Bruce Whealton  
> wrote:
> 
> I would want to package in some way so that when launched, it installs 
> whatever is needed on the end user's computer. How is this done? 

You might want to watch https://www.youtube.com/watch?v=wsczq6j3_bA (Brandon 
Rhodes: The Day of the EXE Is Upon Us - PyCon 2014). 

"It was once quite painful to build your Python app as a single .exe file. 
Support forums filled with lamentations as users struggled with primitive 
tools. But today, two separate tools exist for compiling your Python to real 
machine language! Come learn about how one of the biggest problems in 
commercial and enterprise software has now been solved and how you can benefit 
from this achievement.

Slides can be found at: https://speakerdeck.com/pycon2014 and 
https://github.com/PyCon/2014-slides";

Greetings,


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Converting py files to .exe and .dmg

2016-01-01 Thread Michiel Overtoom

> On 2016-01-01, at 07:43, Brian Simms  wrote:
> 
> when I go into Terminal to run "setup.py install" I keep getting "-bash: 
> command not found".

Try:

  python setup.py install

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: libre office

2016-01-20 Thread Michiel Overtoom

> On 2016-01-20, at 00:01, jim-pc  wrote:
> 
> How do I get data from libre office using python?

Could you be a little more specific? What data? From which part of OpenOffice?

OpenOffice files are actually ZIP files with XML documents in them, but there 
are other ways to interface with OpenOffice.

Greetings,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to PSF

2014-12-28 Thread Michiel Overtoom

On Dec 28, 2014, at 09:54, prateek pandey wrote:

> Yeah, I mean Python Software Foundation. I am a developer and I want to 
> contribute. So, Can you please help me in getting started ? 

https://www.python.org/psf/volunteer/

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What killed Smalltalk could kill Python

2015-01-21 Thread Michiel Overtoom

Hi Steven, you wrote:

> In 2009, Robert Martin gave a talk at RailsConf titled "What Killed
> Smalltalk Could Kill Ruby".

I've yet to watch the video, I'll do that later tonight, but I also remember 
what DHH said about Smalltalk in his FLOSS interview about Rails, with Randal 
Schwartz, in July 2009:

"""
[...] Smalltalk in itself... I tried a few times with some of the images, but 
it's too much of a different world. It's too idealistic for me in some senses. 
It's too much “throw out everything you know and I will show you a new world”. 
I haven't been ready to take that red pill.

I really like that Ruby is sort of, lets extract 80, 90 percent of what awesome 
about that and inject it with some real-world pragmatic approaches, like: You 
can use the text editor you like; You can save files on the file system; You 
can all these things in tracks with the real world. You don't have to leave 
everything behind to jump into this Smalltalk world. To me the whole thing 
about the Smalltalk images which is always just too confusing to me. Why? 
There's all this different distributions, they're not really compatible, it 
just seems like a hassle. I just didn't have the patience to wade through all 
that. But I'm glad somebody else did. I'm glad that all that wisdom is 
available mostly to people using Ruby. So, yeah, again: Not really.
"""

Source: 
http://www.transcribed-interview.com/dhh-rails-david-heinemeier-hansson-interview-randal-schwartz-floss.html

Disclosure: I'm the one who made that transcription, and I recognized it from 
memory.

Greetings,

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Most Diabolical Python Antipattern

2015-01-29 Thread Michiel Overtoom

On Jan 29, 2015, at 18:36, Skip Montanaro wrote:

> There are the occasional instance where I need to recover
> from an exception no matter what caused it.

I had the same need, a while ago, when working on a CherryPy webapp which uses 
a BackgroundTask to parse user-uploaded data and image files (and that can 
throw a variety of exceptions). Any uncaught exception from a BackgroundTask 
will terminate the background thread, which is not good, because one rotten 
input file shouldn't spoil it for the rest. It was also unpredictable what kind 
of exceptions underlying modules would throw without going through all the 
sources with a fine comb. Thus, I wrote a decorator which will catch any 
exception (but not KeyboardInterrupt and SystemExit of course):


# alwayscatch.py - Software by Michiel Overtoom, mot...@xs4all.nl
#
# decorator to wrap an entire function in a try..except block
# to prevent any exception to reach the caller (except SystemExit and 
KeyboardInterrupt)
# because in that case some vital backgroundtask in a webframework will stop 
working.

def alwayscatch(logfunc=None, locus=None):
def deco(wrappee):
def wrapper(*args, **kwargs):
try:
return wrappee(*args, **kwargs)
except KeyboardInterrupt, SystemExit:
raise
except Exception as e:
if logfunc:
logfunc(locus, "Developer sloppyness and/or unrecognized 
situation", e)
else:
print "No logging func defined"
return wrapper
return deco


def frameworklogfunc(locus, msg, exc):
print "[%s] %s: '%s'" % (locus, msg, str(exc))


@alwayscatch(frameworklogfunc, "SUBSYSTEM")
def protectedfunc(x, y, color=23):
return x / y / color


@alwayscatch()
def sillyfunc(a, b, c):
return a / b / c


if __name__ == "__main__":
print protectedfunc(900, 2, 0)
print sillyfunc(900, 2, 0)


...and I used it like this, from the main program:

sizer = cherrypy.process.plugins.BackgroundTask(10, sizer.scan)
sizer.start()

...where the worker function is defined like this:

@alwayscatch(scanlogerror, "SIZE")
def scan():
...

...and the custom logging function: (cherrypy.log in its turn uses the standard 
logging framework)

def scanlogerror(locus, msg, exc):
cherrypy.log("Uncaught exception: %s" % exc, locus, logging.ERROR)


Greetings,

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cairo module

2015-02-04 Thread Michiel Overtoom

Hi Poul,

I recently used cairo in a python project 
(https://github.com/luismqueral/jumpcityrecords). To see the cairo drawing 
directly on the screen I wrote a minimal Gtk application. It's in the 'src' 
directory and is called 'randomdraw.py'. Maybe it is of some help to you.

Greetings,

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-02-25 Thread Michiel Overtoom

On Feb 25, 2015, at 21:45, Mark Lawrence wrote:

> http://www.slideshare.net/pydanny/python-worst-practices

I agree with you that Python lambdas have little use beyond the most trivial 
use cases.

For the non-trivial cases, I like to define a named function which does the 
job. And also provides documentation, just by virtue of being named (and having 
a docstring).

I also tend to do this in JavaScript code, which also can benefit from this.

Greetings,

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2015-03-19 Thread Michiel Overtoom

On Mar 19, 2015, at 08:00, jyothi.n...@gmail.com wrote:

>  file_path = "D:\Tarang\Project\form1.py"

Use either slashes (/), raw strings, or double backslashes:

file_path = "D:/Tarang/Project/form1.py"
file_path = r"D:\Tarang\Project\form1.py"
file_path = "D:\\Tarang\\Project\\form1.py"

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using Python to put a 27-year-old Macintosh on the web

2015-03-23 Thread Michiel Overtoom

On Mar 23, 2015, at 06:36, Steven D'Aprano wrote:

> http://www.keacher.com/1216/how-i-introduced-a-27-year-old-computer-to-the-
> web/

I saw it too, on Hacker News ;-) Awesome. I love(d) my Classic Mac but I 
couldn't stand the slow network connection, I think.

Also, creative use of Flask and BeautifulSoup.

Greetings,


> 
> 
> 
> 
> -- 
> Steve
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: using DictReader() with .decode('utf-8', 'ignore')

2015-04-14 Thread Michiel Overtoom

> ​How can I ​do accomplish decode('utf-8', 'ignore') when reading with 
> DictReader()

Have you tried using the csv module in conjunction with codecs?
There shouldn't be any need to 'ignore' characters.


import csv
import codecs

rs = csv.DictReader(codecs.open(fn, "rbU", "utf8"))
for r in rs:
print(r)

Greetings,

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using Dictionary

2015-04-14 Thread Michiel Overtoom

On Apr 14, 2015, at 15:34, Pippo wrote:

> How can I use dictionary to save the following information?

What a curious question. The purpose of a dictionary is not to save 
information, but to store data as a key -> value mapping:

telbook = {}
telbook["jan"] = "0627832873"
telbook["mary"] = "050-932390"

Or do you mean 'store' when you mention 'save'?

...and to store a bunch of lines you don't need a dictionary either. A list 
would do:

info = [
"#C[Health]",
"#P[Information]",
"#ST[genetic information]",
]

Greetings,

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Messages with a time stamp

2015-05-03 Thread Michiel Overtoom

On May 3, 2015, at 10:22, Cecil Westerhof wrote:

> For testing I want my messages time stamped like:

For progress reporting, I often use the module below (eta.py), which also gives 
a projected time of completion:

import datetime, time, sys
etastart = 0

def eta(done, total, s, reportinterval=100, datetimeformat="%d %b %H:%M:%S"):
global etastart
if done == 0:
etastart = datetime.datetime.now()
if not done % reportinterval:
noww = datetime.datetime.now()
prtnow = noww.strftime(datetimeformat)
if done:
if not isinstance(etastart, datetime.datetime): raise 
RuntimeError("You should call eta() at least once with done=0")
elapsed = noww - etastart
secsperitem = float(elapsed.seconds) / done
totalsecs = secsperitem * total
eta = etastart + datetime.timedelta(0, totalsecs)
prteta = eta.strftime(datetimeformat)
msg = "now %s, eta %s (%d/%d) %s" % (prtnow, prteta, done, total, s)
else:
msg = "now %s (%d/%d) %s" % (prtnow, done, total, s)
sys.stderr.write(msg + "\n")

if __name__ == "__main__":
for i in range(10):
eta(i, 10, "idling for ten seconds", 1, "%H:%M:%S")
time.sleep(1)



-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Immediate Hire: Sr. Java Software Engineer - Oklahoma - GC, US Citizens Onlt

2015-05-11 Thread Michiel Overtoom

On May 11, 2015, at 17:12, nagaraju thoudoju wrote:

> Job Description - Sr. Java Software Engineer


This is a Python mailinglist, not a Java one.

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime.datetime.today()

2015-09-16 Thread Michiel Overtoom

This bit me once. I was comparing a date to a datetime, both representing the 
same day, so I expected them to be the same, but I was wrong. What I should 
have done was extracting the date of the datetime with the .date() function, 
and only then compare it to the other date:

>>> import datetime
>>> a = datetime.datetime.today()
>>> a
datetime.datetime(2015, 9, 16, 16, 57, 45, 150069)
>>> b = datetime.date.today()
>>> a == b
False
>>> a.date()
datetime.date(2015, 9, 16)
>>> a.date() == b
True

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check if a given value is out of certain range

2015-10-05 Thread Michiel Overtoom

Why not use a function?


if outside(x, 0, 10):
print("x has wrong value")
else:
print("x has good value")


where 'outside' is defined as:

def outside(value, lowerbound, upperbound):
return value < lowerbound or value > upperbound  

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: win32com.client .Cells

2015-10-12 Thread Michiel Overtoom

Hi,

> excel_book=Excel.Workbooks.Open('D:\WebPython\Config3.xlsx')

Shouldn't this be:

excel_book=Excel.Workbooks.Open('D:\\WebPython\\Config3.xlsx')
or
excel_book=Excel.Workbooks.Open(r'D:\WebPython\Config3.xlsx')
?


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sets vs lists loop behaviour if size changes

2015-10-14 Thread Michiel Overtoom

> On 14 Oct 2015, at 23:11, candide via Python-list  
> wrote:
> 
> If set size changes during a for loop, a runtime exception is raised

A set is a kind of dictionary (without values). And why it can't be resized, is 
explained by Brandon Rhodes in his excellent talk 'The Mighty Dictionary', 
https://www.youtube.com/watch?v=C4Kc8xzcA68 , starting at 21:24 "Because of 
resizing, a dictionary (or set) can completely reorder during an otherwise 
innocent insert".

Greetings,


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pandas' loading a CSV file problem

2015-10-22 Thread Michiel Overtoom
Hi Ek,

> On 22 Oct 2015, at 14:44, Ek Esawi  wrote:
> 
> f = pd.read_csv('c:/Users/EK Esawi/My Documents/Temp/GOSATemp1.csv')
> File "pandas\parser.pyx", line 1382, in pandas.parser._string_box_utf8 
> (pandas\parser.c:17655)
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 8: 
> invalid start byte

I guess you're on Windows and your CSV file is encoded as Windows-1252. Unless 
you tell Pandas this it'll assume your file is utf-8 encoded.

Try this:

   f = pd.read_csv('c:/Users/EK Esawi/My Documents/Temp/GOSATemp1.csv', 
encoding='windows-1252')

Greetings,




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Version 3.5 required which was not found in the registry

2015-10-27 Thread Michiel Overtoom

> On 27 Oct 2015, at 02:18, luyijie  wrote:
> 
>  when i install  
>  pop "Python Version 3.5 required which was not found in the registry"
>  I do not know how to do...

Wat version of Windows are you using?

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pause and Resuming of a file upload process to AWS S3

2015-10-28 Thread Michiel Overtoom

Hi,

> I wanted to know whether it is possible in python to pause and resume the 
> file upload process to AWS S3

Have a look at s3tools/s3cmd at http://s3tools.org/s3cmd, in 
http://s3tools.org/usage I read:

   --continue-put   Continue uploading partially uploaded files

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UNABLE TO GET IDLE TO RUN

2015-10-30 Thread Michiel Overtoom
Hi,

Laura wrote:
> I think that it would be useful if IDLE spit out a warning

An ounce of prevention is worth a pound of cure. Maybe it's an idea that IDLE 
gives a warning when you're trying to save a file with a name that would shadow 
an existing module?

Greetings,






-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UNABLE TO GET IDLE TO RUN

2015-10-31 Thread Michiel Overtoom

> On 31 Oct 2015, at 06:59, Terry Reedy  wrote:
> This is a different issue than IDLE avoiding clashes.  I opened
> https://bugs.python.org/issue25522

Terry, thanks for recording this into the issue tracker.

I'd go even a step further. I think IDLE should not only warn, but completely 
prevent saving a file which shadows a stdlib module, which will effectively 
render Python unusable. I remember from a few weeks back, a teacher with the 
same problem posted this on the mailinglist. Eventually she had a technician 
coming in to reinstall Windows, just to fix this problem ;-) What an overkill...

Greetings,


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: installer user interface glitch ?

2015-11-01 Thread Michiel Overtoom

> On 01 Nov 2015, at 16:43, rurpy--- via Python-list  
> wrote:
> 
> Why, oh why, do the python.org front page and other pages that offer
> a Windows download not say a word about it not running on Windows XP?

I'm also curious why Python 3.5 won't run on Windows XP. Which features does it 
use that require Windows 7 or higher? Or is the decision to not support Windows 
XP based on Microsoft ending the product support lifecycle for XP?

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Puzzled

2015-11-03 Thread Michiel Overtoom

> On 03 Nov 2015, at 05:46, Michael Torrie  wrote:
> Sometimes on Windows you can double-click a python file and it will run.

The first thing I do on Windows after installing Python: edit the registry
so that the 'open' key is changed to 'run', and 'edit with IDLE' becomes 'open'.

I like to see my scripts in IDLE before I run them ;-)

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: using binary in python

2015-11-09 Thread Michiel Overtoom

> On 08 Nov 2015, at 22:27, kent nyberg  wrote:
> 
> Well, lets assume I want to write and read binary.  How is it done?

With the functions 'open()' and 'read()' and 'write()'. If you're on Windows, 
don't forget to include a 'b' in the mode string of the open() call, otherwise 
Python will assume that you're opening a text file.

You also might want to look into the 'struct' module, functions 'pack()' and 
'unpack()'. They convert python values to their binary representation which is 
used in binary files.

Greetings,



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: write data in Excel using python

2015-11-16 Thread Michiel Overtoom

Hi,

> On 16 Nov 2015, at 18:14, syedmwaliul...@gmail.com wrote:
> For some reason it doesn't save the file.

Did you get an error message?

> excel.activeWorkbook.SaveAs ("c:\TurnData.xlsx")

When you use backslashes in strings, don't forget to escape them:

> excel.activeWorkbook.SaveAs("c:\\TurnData.xlsx")

or use raw strings:

> excel.activeWorkbook.SaveAs(r"c:\TurnData.xlsx")

Greetings,


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how do I learn python ?

2015-11-19 Thread Michiel Overtoom

> On 18 Nov 2015, at 05:58, 夏华林  wrote:
> (nothing)

You might want to start at https://www.python.org/about/gettingstarted/

PS. Leaving the body of an email or usenet article empty is considered bad form.

Greetings,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (-1)**1000

2014-10-22 Thread Michiel Overtoom

On Oct 22, 2014, at 12:29, Peter Otten wrote:

> That looks like log(a) while a parity check takes constant time:
> $ python3 -m timeit -s 'a = 10**10' 'a & 1'


Do you mean 'parity' as in http://en.wikipedia.org/wiki/Parity_bit ?  Because a 
parity bit denotes whether the *number* of '1' bits is even or odd, not the 
value of the least significant bit.

Greetings,

-- 
"You can't actually make computers run faster, you can only make them do less." 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to represent a sequence of raw bytes

2008-12-21 Thread Michiel Overtoom
On Monday 22 December 2008 03:23:03 Steven Woody wrote:

> 2.  char buf[] = {0x11, 0x22, 0x33, ... }
>
> What's the equivalent representation for above in Python?

>>> buf="\x11\x22\33"
>>> for b in buf: print ord(b)
...
17
34
27
>>>


Greetings, 

-- 
"The ability of the OSS process to collect and harness 
the collective IQ of thousands of individuals across 
the Internet is simply amazing." - Vinod Vallopillil 
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sqlite3 cursor and imbricated for loop

2008-11-11 Thread Michiel Overtoom

Charles V. wrote:

It seems the second call to execute modify the first cursor. Is it normal ? 
How am I suppose to write this ?


Maybe introduce a second cursor?

import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
d = conn.cursor() # second cursor
c.execute('''create table stocks
(date text, trans text, symbol text,
 qty real, price real)''')
c.execute("insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)")
c.execute("insert into stocks values ('2006-01-06','BUY','RHAT',100,20.0)")
c.execute("insert into stocks values ('2006-01-07','BUY','RHAT',100,15.0)")
c.execute("insert into stocks values ('2006-01-08','BUY','RHAT',100,10.0)")
conn.commit()
c.execute("select * from stocks")
for s in c:
   print s[0]
   d.execute("select * from stocks where price<20") # use the second cursor
   for s in d:
  print '  '+s[0]
c.close()


Outputs:

2006-01-05
  2006-01-07
  2006-01-08
2006-01-06
  2006-01-07
  2006-01-08
2006-01-07
  2006-01-07
  2006-01-08
2006-01-08
  2006-01-07
  2006-01-08


--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to make arrays from Lists

2008-11-16 Thread Michiel Overtoom

[EMAIL PROTECTED] wrote:


x = [[0] * ncols for i in nrows]


That gives an error... small typo corrected:

y = [[0] * ncols for i in range(nrows)]

Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Decorators

2009-03-06 Thread Michiel Overtoom
Johnny wrote...

>Can anyone explain to me what are decorators for? What are advantages
>of using them?

A tutorial article about decorators from Bruce Eckel:

http://www.artima.com/weblogs/viewpost.jsp?thread=240808


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: What way is the best to check an empty list?

2009-03-25 Thread Michiel Overtoom



On 25 Mar 2009, at 21:29 , Stef Mientki wrote:


Now it would be nice to allow iteration over others too, like None .
   a = None
   for item in a :
 do_something_with_item



I saw this technique used in CherryPy:

>>> a=None
>>> for item in a or []:
...print item
...
>>> a=[1,2,3]
>>> for item in a or []:
... print item
...
1
2
3
>>>



--
http://mail.python.org/mailman/listinfo/python-list


Re: PyFits for Windows?

2009-03-28 Thread Michiel Overtoom

W. eWatson wrote:

It looks like PyFits downloads are for Linux. Isn't there anything available 
for Win (xp)?


According to http://www.stsci.edu/resources/software_hardware/pyfits:

"PyFITS’s source code is pure Python. It requires Python version 2.3 or 
newer. PyFITS also requires the numarray module. PyFITS uses python’s 
distutils for its installation. To install it, unpack the tar file and 
type: python setup.py install"


It looks like PyFits is platform-independent.

Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: error in tutorial for 3.0, section 9.3.3

2009-05-23 Thread Michiel Overtoom


Vincent writes:

> you kinda expect MyClass to have counter in it.

Yeah, that makes sense. These instance variables are often initialized 
in the __init__ method:



class Counter(object):
def __init__(self,initialvalue):
self.value=initialvalue
def inc(self):
self.value+=1
def dec(self):
self.value-=1

beans=Counter(123)
beans.inc()
beans.inc()
beans.dec()
print beans.value

# the output of the program is: 124

Greetings,


--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: GUI Programming

2009-05-28 Thread Michiel Overtoom
On Sunday 12 April 2009 15:07:11 Gabriel wrote:

> I'm python newbie and i need to write gui for my school work in python.
> I need to write it really quick, because i haven't much time .)

Try Tkinter, which is included by default with most Python installations.

Writing simple programs is easy like:

   from Tkinter import *
   root=Tk()
   w=Label(root, text="Hello, world!")
   w.pack()
   root.mainloop()

See the tutorial at 
http://www.pythonware.com/library/tkinter/introduction/hello-tkinter.htm


Greetings, 

-- 
"The ability of the OSS process to collect and harness 
the collective IQ of thousands of individuals across 
the Internet is simply amazing." - Vinod Valloppillil 
http://www.catb.org/~esr/halloween/halloween4.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: formatting list -> comma separated (slightly different)

2008-07-09 Thread Michiel Overtoom
Paul & Robert wrote...

> d = ["soep", "reeds", "ook"]
>print ', '.join(d)
> soep, reeds, ook

I occasionally have a need for printing lists of items too, but in the form:
"Butter, Cheese, Nuts and Bolts".  The last separator is the word 'and'
instead of the comma. The clearest I could come up with in Python is below.
I wonder if there is a more pythonic solution for this problem.  Maybe
something recursive?

Greetings,


'''
Formatting a sequence of items such that they are separated by
commas, except the last item, which is separated by the word 'and'.

Used for making lists of dates and items more human-readable
in generated emails and webpages.

For example:

Four friends have a dinner: Anne, Bob, Chris and Debbie
Three friends have a dinner: Anne, Bob and Chris
Two friends have a dinner: Anne and Bob
One friend has a dinner: Anne
No friend has a dinner:

 ['Anne','Bob','Chris','Debbie'] -> "Anne, Bob, Chris and Debbie"
 ['Bob','Chris','Debbie'] -> "Bob, Chris and Debbie"
 ['Chris','Debbie'] -> "Chris and Debbie"
 ['Debbie'] -> "Debbie"
 [] -> ""

'''

def pretty(f):
if len(f)==0: return ''
if len(f)==1: return f[0]
sepwithcommas=f[:-1]
sepwithand=f[-1]
s=', '.join(sepwithcommas)
if sepwithand:
s+=' and '+sepwithand
return s

friends=['Anne','Bob','Chris','Debbie','Eve','Fred']
while True:
print friends,'->',pretty(friends)
if friends:
friends.pop(0)
else:
break





-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Graphics

2008-07-10 Thread Michiel Overtoom
Vanam wrote...

> I want to know whether is there anything that has 
> to be installed in addition to python 2.5
>
> from gasp import *

You have to install the 'gasp' package too.

  https://launchpad.net/gasp-code/stable-0.1.x/0.1.1


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: parsing incoming emails

2008-07-10 Thread Michiel Overtoom
Ahmed wrote...

> I am working on a project where I need to parse incoming emails
> (Microsoft outlook)

I'm not sure if you are able to bypass Outlook (and have Python fetch the
mail itself using poplib), but if you are, the following code might be
useful.  I use this to pry apart emails which might contain multiple MIME parts.

from email.Parser import Parser
from rfc822 import parseaddr
import poplib
import smtplib

popserver="pop.site.com"
popuser="[EMAIL PROTECTED]"
poppassword="secret"

# split a message into an header- and body part
def separate(msg):
if isinstance(msg,str):
msg=msg.split('\n')
emptyline=msg.index('')
return msg[:emptyline],msg[emptyline+1:]


# return a certain headerline from the headers
def headerline(header,tag="From: "):
for h in header:
if h.startswith(tag):
return h[len(tag)+1:]
return ""


# enumerate recursively the contents of a MIME message
# remember the first text/plain and text/html part(s) that is found
# also remember if any other parts were found (like attachments)
#
def enummimeparts(msg,extract,level=1,verbose=False):
m=Parser().parsestr(msg)
if m.is_multipart():
if verbose: print '\t'*level,'multipart'
for part in m.get_payload():
enummimeparts(part.as_string(),extract,level+1,verbose)
else:
t=m.get_content_type()
if verbose: print '\t'*level,t
if t=="text/plain":
if not "text/plain" in extract:
headers,body=separate(m.as_string())
extract["text/plain"]='\n'.join(body)
else:
extract["others"]=True
elif t=="text/html":
if not "text/html" in extract:
headers,body=separate(m.as_string())
extract["text/html"]='\n'.join(body)
else:
extract["others"]=True
else:
extract["others"]=True


# extract the first 'text/plain' and 'text/html' mime-parts from a message
def extracttext(msg):
extract={}
enummimeparts(msg,extract)
return
extract.get("text/plain",None),extract.get("text/html",None),extract.get("ot
hers",False)


def processmessage(msgnr):
# get a message from the POP server, extract the parts
response,lines,bytes=pop.retr(msgnr)
msg='\n'.join(lines)
headers,body=separate(lines)
name,fromaddress=parseaddr(headerline(headers,"From:"))
subject=headerline(headers,"Subject:")
logging.info(subject+" ("+fromaddress+")")
(plain,html,others)=extracttext(msg)
# prefer flat text; if not present in the message, fallback to HTML
content (if any)
texttoprocess=""
if plain:
texttoprocess=plain
elif html:
texttoprocess=html
# now do something useful with the text
processtext(texttoprocess)
# delete message from pop server after processing
pop.dele(msgnr)


# connect to the pop server and process all messages
logging.info("Checking pop server '%s', user '%s'" % (popserver,popuser))
pop=poplib.POP3(popserver)
pop.user(popuser)
pop.pass_(poppassword)
stat=pop.stat()
if stat[0]:
for n in range(stat[0]):
processmessage(n+1)
pop.quit()


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone suggest a date peocedure...

2008-07-10 Thread Michiel Overtoom


Ron wrote:


Now all I need to know is how to
plug the date into the datetime object from a string.


You could use simple string manipulation:

>>> import datetime
>>> a="20081031"
>>> d=datetime.date(int(a[0:4]),int(a[4:6]),int(a[6:8]))
>>> d
datetime.date(2008, 10, 31)
>>> print d
2008-10-31

Greetings,

--
http://mail.python.org/mailman/listinfo/python-list


Re: Using the Random Module.

2008-07-11 Thread Michiel Overtoom
You wrote...

>Is there a better way to do that besides doing this:
>
random.randint(0, 9)
>09657398671238769

Maybe this?

random.randint(0, 9e16)


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Help with BeautifulSoup

2008-07-12 Thread Michiel Overtoom
Alex wrote...
>
>Okay, heres the general idea of the html I have to work with:
>
>
>   noun
>   
>   
>   
>   
>   verb
>   
>   
>   
>
>
>Okay, I left off some stuff. 

I wish you didn't, or at least provided an URL where I can get the page
which you are trying to parse.  Now I don't have a valid testcase to tinker
with.  And maybe you can also show your code which you already came up with.


> I can easily get the tables but it is the span's than I am having trouble
with. 

I can't see any SPAN tags in the example you provided.

Greetings,

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Use of index

2008-07-12 Thread Michiel Overtoom
SUBHABRATA wrote...

> Now, my q is can we use index like find?

Yes, you can.  There is only a difference when the string is not found: the
'find()' function will return -1, whereas 'index()' function will raise a
ValueError exception.

For example:

>>> b="A spaghetti monster is always great"
>>> print "monster" in b
True
>>> print b.find("monster")
12
>>> print b.index("monster")
12
>>> print b.find("pasta")
-1
>>> print b.index("pasta")
Traceback (most recent call last):
  File "", line 1, in 
print b.index("pasta")
ValueError: substring not found
>>> 


This is also documented in the built-in help:

>>> help(b.index)
Help on built-in function index:

index(...)
S.index(sub [,start [,end]]) -> int

Like S.find() but raise ValueError when the substring is not found.


>>> help(b.find)
Help on built-in function find:

find(...)
S.find(sub [,start [,end]]) -> int

Return the lowest index in S where substring sub is found,
such that sub is contained within s[start,end].  Optional
arguments start and end are interpreted as in slice notation.

Return -1 on failure.

Hope this helps,

Greetings

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Determining when a file has finished copying

2008-07-14 Thread Michiel Overtoom
Ethan wrote:

> One more option may be to attempt to rename 
> the file -- if it's still open for copying, that will fail; 
> success indicates the copy is done.  

Caveat -- this is dependent on the operating system!

Windows will indeed not allow you to rename or delete a file that's still
open for writing by another process, at least not when the file is on a
local NTFS filesystem, but don't count on this on Unix or networked
filesystems.  There you can easily rename, move or delete a filename from a
directory whilst other processes still write to it. After all, a directory
is nothing else than a list of filenames which map to certain inodes.

Greetings,

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Simplify Code

2008-07-15 Thread Michiel Overtoom
Victor wrote...

># del is used to determine if should reset the lower header values to ''
>del = 0

Apart from many other things that spring to mind, I already see an obvious
flaw: 'del' is a keyword, or a 'reserved word' in Python. It is used to
remove variables from the namespace. Tip: Use some other name as a variable,
eg. 'deletethisone'.

Greetings,


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Type Problem

2008-07-15 Thread Michiel Overtoom
Victor wrote...

>len = len(dirs)

The function 'len' is a built-in function in Python. If you assign an
integer to the name 'len', that will replace the function with an int. And
you can't call an int.

My suggestion: Do not use 'len' as a variable name. Use something else, like:

directorycount=len(dirs)

Greetings,

>>> type(len)


>>> print len("Victor")
6

>>> len=42

>>> type(len)


>>> len("Victor")
Traceback (most recent call last):
  File "", line 1, in 
len("Victor")
TypeError: 'int' object is not callable

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters Being Misread

2008-07-15 Thread Michiel Overtoom
Victor wrote...

 import binascii
 binascii.unhexlify('\x0c')
>TypeError: Odd-length string
>What gives here?

The function unhexlify() wants an even-length string. From the online help:

>>> help(binascii.unhexlify)
unhexlify(...)
a2b_hex(hexstr) -> s; Binary data of hexadecimal representation.
hexstr must contain an even number of hex digits (upper or lower case).
This function is also available as "unhexlify()"

And you use it like this:

>>> binascii.unhexlify("41")
'A'


You feed it data without any '0x' prefixes.

What are you trying to do? Parsing an RTF file which contains unicode
characerts, encoded as hexadecimal?

Greetings,


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Is it legal to rebuild Python.exe to include Version property tab?

2008-07-15 Thread Michiel Overtoom
Ward wrote...

> Can we rebuild Python.exe to include the various "version" 
> information?

Why rebuild it? You can use a resource editor tool to add/edit/delete the
VERSIONINFO from any Windows executable, including Python.exe ;-)

Greetings,

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Simplify Code

2008-07-15 Thread Michiel Overtoom
Victor wrote...

># Headers are kept in order to determine nesting of chapters
># They are labeled according to font size

I'm not sure what you're trying to achieve (I can't divine it from your
example code), but I suspect that a dictionary of sizes and header texts is
somewhat more manegable than a slew of separate variables h12, h14, h16,
h22, h36 etc...

Maybe this gives an idea:


# this could come from an input file or a parser
source=(
(18,"Hello"),
(36,"Greetings"),
# (11,"Boeh") , # uncomment to test this illegal size
(36,"You too"),
(12,"Bye"),
)

# for each font size, remember the last seen header text
headers={12:"", 14:"", 18:"", 22:"", 26:"", 36:""}

# process the source, collect the header texts
for (size,text) in source:
  if not size in headers:
raise KeyError("%d is an illegal size. It must be one of %s" %
(size,sorted(headers)))
  headers[size]=text

# do something with the collected header texts
for h in sorted(headers):
  print h,headers[h]
  

Greetings,

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Kids

2008-07-15 Thread Michiel Overtoom
Sean wrote...

> Pretty cool!!  Our base will be *much* bigger in about twenty years.
> I remember doing Basic on my dads Apple IIe.

Gee, I wish Python existed back then. I had to endure Commore Basic on the
PET2001. The biggest challenge was how to fit the program in 8K...  It
didn't take me long to switch to 6502 machine language to get more out of
it.  And I was a really happy kid when the S100 systems with FORTRAN and
simple C compilers came along ;-)  I wish I still had my original K&R
"Programming C" and Kernighan&Plaughers "Software Tools" using RATFOR, but
they have been lost in the mist of years.

Greetings,

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: win32api not found?

2008-07-19 Thread Michiel Overtoom
On Saturday 19 July 2008 21:13:04 Lamonte Harris wrote:

> Where can I get the win32api module? I been searching all day on google and
> nothing, i installed
> https://sourceforge.net/project/showfiles.php?group_id=78018 which requires
> win32api and its not found...

What are the actions you do and the commands you give, and what is the precise 
error you get?

Greetings, 

-- 
"The ability of the OSS process to collect and harness 
the collective IQ of thousands of individuals across 
the Internet is simply amazing." - Vinod Vallopillil 
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-19 Thread Michiel Overtoom
On Saturday 19 July 2008 22:30:29 Dennis Lee Bieber wrote:

>   I still wonder who came up with the Commodore PET -- Personal
> Electronic Transactor... yeesh... But the "Personal" was already in play
> way back then.

Probably Chuck Peddle, Jack Tramiel or Leonard Tramiel.

For your amusement: http://en.wikipedia.org/wiki/PET_2001

Greetings, 

-- 
"The ability of the OSS process to collect and harness 
the collective IQ of thousands of individuals across 
the Internet is simply amazing." - Vinod Vallopillil 
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-20 Thread Michiel Overtoom
Giveitawhril wrote...

> REAL WORLD programmers who want to be generally useful go 
> and learn C#.

No: Real programmers first eat a quiche and then return to their Pascal
programming.


> But the SOURCE is some old, high level language which no one wants to 
> use anymore! 

C is alive and kicking. Every language has its place.
Plus, there exists implementations of Python written in Python itself;
see PyPy: http://codespeak.net/pypy/dist/pypy/doc/home.html


> Just noting that, if it is written in C, that throws a curve at me 
> in trying to balance the value of learning Python vs. some other 
> major language.

Many major text/word processing programs (Emacs, vi, MS-Word) are also
written in C. Does that mean you should do all your text processing in C?

Greetings,


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-22 Thread Michiel Overtoom
giveitawhril2008 wrote...

> I think someone should write a compiler, "Revenge of BASIC."

Your remark made an immediate association with me with the following soundtrack:

http://www.empire-of-the-claw.com/files/Empire%20of%20The%20Claw%20-%20Tranc
e%20of%20the%2080's%20Arcade.mp3

"A creature for my amusement"

Greetings,

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: maximum value in a column of file

2008-07-23 Thread Michiel Overtoom
Maurizio wrote...

> the problem is that i don't know how to put the column of the file in an 
> array. (i'm new in phyton).

Give us an example of how your file looks, and what you want to 
extract from it, so that we don't have to guess.

Greetings,

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: How to know a top directory?

2008-08-23 Thread Michiel Overtoom
Grigory wrote...

> I have path "/this/is/path" and I wanna get "/this/is".
>Also I want to use it as platform independent. If I want to pass "c:
>\that\path" then I need to get "c:\that".

import os
print os.path.split("/home/user/motoom")[0]
print os.path.split("c:\\prj\\techniques\\python")[0]


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: how can i use lxml with win32com?

2009-10-25 Thread Michiel Overtoom

elca wrote:


yes i want to extract this text 'CNN Shop' and linked page
'http://www.turnerstoreonline.com'.


Well then.
First, we'll get the page using urrlib2:

doc=urllib2.urlopen("http://www.cnn.com";)

Then we'll feed it into the HTML parser:

soup=BeautifulSoup(doc)

Next, we'll look at all the links in the page:

for a in soup.findAll("a"):

and when a link has the text 'CNN Shop', we have a hit,
and print the URL:

if a.renderContents()=="CNN Shop":
print a["href"]


The complete program is thus:

import urllib2
from BeautifulSoup import BeautifulSoup

doc=urllib2.urlopen("http://www.cnn.com";)
soup=BeautifulSoup(doc)
for a in soup.findAll("a"):
if a.renderContents()=="CNN Shop":
print a["href"]


The example above can be condensed because BeautifulSoup's find function 
can also look for texts:


print soup.find("a",text="CNN Shop")

and since that's a navigable string, we can ascend to its parent and 
display the href attribute:


print soup.find("a",text="CNN Shop").findParent()["href"]

So eventually the whole program could be collapsed into one line:

print 
BeautifulSoup(urllib2.urlopen("http://www.cnn.com";)).find("a",text="CNN 
Shop").findParent()["href"]


...but I think this is very ugly!


> im very sorry my english.

You English is quite understandable.  The hard part is figuring out what 
exactly you wanted to achieve ;-)


I have a question too.  Why did you think JavaScript was necessary to 
arrive at this result?


Greetings,
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can i use lxml with win32com?

2009-10-25 Thread Michiel Overtoom

elca wrote:


actually what i want to parse website is some different language site.


A different website?  What website?  What text?  Please show your actual 
use case, instead of smokescreens.




so i was quote some common english website for easy understand.   :)


And, did you learn something from it?  Were you able to apply the 
technique to the other website?




by the way, is it possible to use with PAMIE and beautifulsoup work
together?


If you define 'working together' as like 'PAMIE produces a HTML text and 
BeautifulSoup parses it', then maybe yes.


Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can i use lxml with win32com?

2009-10-25 Thread Michiel Overtoom

elca wrote:


im sorry ,also im not familiar with newsgroup.


It's not a newsgroup, but a mailing list. And if you're new to a certain 
community you're not familiar with, it's best to lurk a few days to see 
how it is used.



so this position is bottom-posting position? 


It is, but you should also cut away any quoted text that is not directly 
related to the answer.
Otherwise people have to scroll many screens full of text before they 
can see the answer.



> how can i keep open only one windows? not open several windows.

The trick is to not instantiate multiple PAMIE objects, but only once, 
and reuse that.

Like:

import time
import PAM30
ie=PAM30.PAMIE( )

ie.navigate("http://www.cnn.com";)
text1=ie.getPageText()

ie.navigate("http://www.nu.nl";)
text2=ie.getPageText()

ie.quit()
print len(text1), len(text2)


But still I think it's unnecessary to use Internet Explorer to get 
simple web pages.
The standard library "urllib2.urlopen()" works just as well, and doesn't 
rely on Internet Explorer to be present.


Greetings,


--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can i use lxml with win32com?

2009-10-25 Thread Michiel Overtoom

elca wrote:


http://news.search.naver.com/search.naver?sm=tab_hty&where=news&query=korea+times&x=0&y=0
that is korea portal site and i was search keyword using 'korea times'
and i want to scrap resulted to text name with 'blogscrap_save.txt'


Aha, now we're getting somewhere.

Getting and parsing that page is no problem, and doesn't need JavaScript 
or Internet Explorer.


import urllib2
import BeautifulSoup
doc=urllib2.urlopen("http://news.search.naver.com/search.naver?sm=tab_hty&where=news&query=korea+times&x=0&y=0";)
soup=BeautifulSoup.BeautifulSoup(doc)


By analyzing the structure of that page you can see that the articles 
are presented in an unordered list which has class "type01".  The 
interesting bit in each list item is encapsulated in a  tag with 
class "sh_news_passage".  So, to parse the articles:


ul=soup.find("ul","type01")
for li in ul.findAll("li"):
dd=li.find("dd","sh_news_passage")
print dd.renderContents()
print

This example prints them, but you could also save them to a file (or a 
database, whatever).


Greetings,



--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Handling large datastore search

2009-11-03 Thread Michiel Overtoom

Ahmed Barakat wrote:

In case I have a  huge datastore (1 entries, each entry has like 6 
properties)


Can you show some sample entries?  That way we can get an idea how your 
datastore looks like.


By the way, 1 doesn't sound that much. At work I create python 
programs which do data processing and ofter have this much entries in a 
dictionary, often more.



Is the conversion to XML a good solution, or it is not?


XML is meant to be an exchange format; it is not designed for storage or 
fast retrieval.


Greetings,



--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding the CPython dict implementation

2010-03-16 Thread Michiel Overtoom

On 16 Mar 2010, at 12:46 , Steven D'Aprano wrote:

> On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote:
> 
>> I found this PyCon2010 presentation to be excellent: The Mighty
>> Dictionary, Branden Craig Rhodes, 30 min.
>> http://pycon.blip.tv/file/3264041/
> 
> 
> Unfortunately, that clip seems to be unwatchable, at least for me. It 
> crashed the Netscape plugin in Konqueror, and crashed Firefox. When I 
> downloaded the ogv file, it crashed MPlayer and Kaffeine.

It played in VLC without problems.

Greetings,


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a class at run-time

2010-03-25 Thread Michiel Overtoom

On 2010-03-25 23:00, Michel wrote:


I'm trying to dynamically create a class. What I need is to define a
class, add methods to it and later instantiate this class. Methods
need to be bound to the instance though, and that's my problem.


Maybe this snippet is of any help?

import functools

class Template(object):
pass

def printmyname(self):
print self.name

t=Template()
t.name="Pete"
t.printmyname=functools.partial(printmyname,t)

u=Template()
u.name="Mary"
u.printmyname=functools.partial(printmyname,u)

t.printmyname()
u.printmyname()

Greetings,


--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do any debuggers support "edit and continue?"

2010-05-13 Thread Michiel Overtoom

On 2010-05-13 00:07, Joel Koltner wrote:


Hey, a lot of people would argue that Python's lack of strong typing and
data/member protection (from one class to another) encourages sloppy
programming too.  :-)


You're being ironic, aren't you?

Python does have strong typing (many people confuse that with static 
typing), see http://www.artima.com/weblogs/viewpost.jsp?thread=7590


And for data member protection, there is the 'consenting adult' rule. 
Touch instance variables which start with an underscore on your own risk.


Greetings,

--
"Open-source projects are run by people who are self-selected to actually
care about the software, as opposed to resentful wage slaves for
whom control over their work product is minimal and development is
just another stretch of cubicle time." - ESR, http://esr.ibiblio.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Periodic table gets a new element

2009-06-11 Thread Michiel Overtoom

MRAB wrote:


Element 112 is to be named. Do you think we could persuade the
scientists to name it "Pythonium"? :-)


What did Python do to deserve this?  I think 'Hofmannium' is a more 
appropriate name ;-)


On the other hand, if the scientists used Python on their equipment with 
which they discovered the new element, the name 'Pythonium' is of course 
totally acceptable.


Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE / Python 2.5 under Jaunty

2009-06-24 Thread Michiel Overtoom


Duncan Smith wrote:

> IDLE now refuses to

respond to left click events (for code editing, menus etc. respond as
expected).  If I right click, then left click I can move the cursor, but
that's not ideal. 

>

So, has anybody else had the left click issue with IDLE (and solved it)?


Irritating problem, isn't it?  I experience the same on FreeBSD with Tk8.5.
I had to downgrade to Tk8.4, which has ugly fonts.

See http://bugs.python.org/issue2995

"Moving the mouse over the text widget changes the cursor to the I-beam
as expected, but click on text doesn't position the beam at the mouse
position.  It is also impossible to select text with the mouse.
Selecting text with shift-arrow keys works, however."

It's closed because it doesn't seem related to Python.

Greetings,



--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem reading file with umlauts

2009-07-07 Thread Michiel Overtoom

Claus Hausberger wrote:


I have a text file with is encoding in Latin1 (ISO-8859-1). I can't
change that as I do not create those files myself. I have to read
those files and convert the umlauts like ö to stuff like &oumol; as
the text files should become html files.


umlaut-in.txt:

This file is contains data in the unicode
character set and is encoded with utf-8.
Viele Röhre. Macht spaß!  Tsüsch!


umlaut-in.txt hexdump:

00: 54 68 69 73 20 66 69 6C  65 20 69 73 20 63 6F 6E This file is con
10: 74 61 69 6E 73 20 64 61  74 61 20 69 6E 20 74 68 tains data in th
20: 65 20 75 6E 69 63 6F 64  65 0D 0A 63 68 61 72 61 e unicode..chara
30: 63 74 65 72 20 73 65 74  20 61 6E 64 20 69 73 20 cter set and is
40: 65 6E 63 6F 64 65 64 20  77 69 74 68 20 75 74 66 encoded with utf
50: 2D 38 2E 0D 0A 56 69 65  6C 65 20 52 C3 B6 68 72 -8...Viele R..hr
60: 65 2E 20 4D 61 63 68 74  20 73 70 61 C3 9F 21 20 e. Macht spa..!
70: 20 54 73 C3 BC 73 63 68  21 0D 0A 00 00 00 00 00  Ts..sch!...


umlaut.py:

# -*- coding: utf-8 -*-
import codecs
text=codecs.open("umlaut-in.txt",encoding="utf-8").read()
text=text.replace(u"ö",u"oe")
text=text.replace(u"ß",u"ss")
text=text.replace(u"ü",u"ue")
of=open("umlaut-out.txt","w")
of.write(text)
of.close()


umlaut-out.txt:

This file is contains data in the unicode
character set and is encoded with utf-8.
Viele Roehre. Macht spass!  Tsuesch!


umlaut-out.txt hexdump:

00: 54 68 69 73 20 66 69 6C  65 20 69 73 20 63 6F 6E This file is con
10: 74 61 69 6E 73 20 64 61  74 61 20 69 6E 20 74 68 tains data in th
20: 65 20 75 6E 69 63 6F 64  65 0D 0D 0A 63 68 61 72 e unicode...char
30: 61 63 74 65 72 20 73 65  74 20 61 6E 64 20 69 73 acter set and is
40: 20 65 6E 63 6F 64 65 64  20 77 69 74 68 20 75 74  encoded with ut
50: 66 2D 38 2E 0D 0D 0A 56  69 65 6C 65 20 52 6F 65 f-8Viele Roe
60: 68 72 65 2E 20 4D 61 63  68 74 20 73 70 61 73 73 hre. Macht spass
70: 21 20 20 54 73 75 65 73  63 68 21 0D 0D 0A 00 00 !  Tsuesch!.





--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Equivalent for dd & fold

2009-07-15 Thread Michiel Overtoom

seldan24 wrote:


what can I use as the equivalent for the Unix 'fold' command?


def fold(s,len):
while s:
print s[:len]
s=s[len:]

s="A very long string indeed. Really that long? Indeed."
fold(s,10)

Output:

A very lon
g string i
ndeed. Rea
lly that l
ong? Indee
d.

Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread Michiel Overtoom


I got success with the following code (python 2.6.2):

import turtle
turtle.reset()
for i in range(4):
   turtle.forward(50)
   turtle.right(90)
can=turtle.getscreen().getcanvas()
can.postscript(file="tmp.ps")


--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Equivalent for dd & fold

2009-07-16 Thread Michiel Overtoom

seldan24 wrote:


I know that Emile suggested that I can slice out the substrings rather
than do the gradual trimming of the string variable as is being done
by moving around the length. 


An excellent idea.

def fold(s,chunklength):
offset=0
while offsethttp://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: 'del' function for Dictionary

2009-07-17 Thread Michiel Overtoom

mayank gupta wrote:

after analyzing the time taken by the code,

What code?


--
http://mail.python.org/mailman/listinfo/python-list


Re: Python graphics / imaging library

2009-07-18 Thread Michiel Overtoom

Peter Chant wrote:


what's the most appropriate (maintained) graphics library to use?  PIL seems
to have last been updated in 2006 http://www.pythonware.com/products/pil/
and GD seems to be even older.  Don't want to go down a dead end.


Contrary to organic material, software doesn't rot when it gets older.

PIL is pretty complete for the task it was designed to do, pretty 
debugged during the past years, and pretty much 'finished' -- it doesn't 
need frequent updates anymore.


Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python graphics / imaging library

2009-07-18 Thread Michiel Overtoom

Peter Chant wrote:


what do people generally use now?


I can only speak for myself... I use PIL ;-)

Greetings,

--
http://mail.python.org/mailman/listinfo/python-list


Re: On out-of-date Python Applications

2009-07-19 Thread Michiel Overtoom

Virgil Stokes wrote:

> some of these applications will

not install on the latest version of Python.


Which version of Python precisely?



--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Michiel Overtoom

Phillip wrote:


Specifically the "differences" between lists and tuples have us
confused and have caused many "discussions" in the office. We
understand that lists are mutable and tuples are not, but we're a
little lost as to why the two were kept separate from the start. They
both perform a very similar job as far as we can tell.


Yes, but because of their immutability you can use tuples as dictionary 
keys (only if they contain immutable objects).

Lists can't be used as dictionary keys.

Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: An assessment of Tkinter and IDLE

2009-08-28 Thread Michiel Overtoom

r wrote:


Whats the use of Tkinter if the docs are in TCL. Just
learn TCL and skip the Python middleman. 


But Mark's tutorial at http://www.tkdocs.com/tutorial/index.html allows 
you to select 'Python' as one of the languages you want to see the 
example code in.


Too bad that the 'ttk' widgets are not mainstream yet.

Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: your favorite debugging tool?

2009-08-30 Thread Michiel Overtoom

Esmail wrote:


What is your favorite tool to help you debug your
code? 


import pdb
pdb.set_trace()

pdb has commands to inspect code, variables, set breakpoints, watches, 
walk up and down stack frames, single-step through the program, run the 
rest of the function, run until return, etc...


http://www.ferg.org/papers/debugging_in_python.html

http://onlamp.com/pub/a/python/2005/09/01/debugger.html

http://plone.org/documentation/how-to/using-pdb

http://docs.python.org/library/pdb.html

Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list