Suppose I had a function like the following:
#
def y_n(prompt=Answer yes or no):
while True:
answer = raw_input(prompt)
if answer in ['y', 'Y', 'yes']:
print You said yes!
break
elif answer in ['n', 'N', 'no']:
print You
Quoting [EMAIL PROTECTED]:
Send Tutor mailing list submissions to
tutor@python.org
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
You
2006/4/18, Danny Yoo [EMAIL PROTECTED]:
H Can you send a link to the text that's causing performance
issues? It might be possible that someone here might isolate the
performance problem. (Hey, it happened before with BeautifulSoup...
*grin*)
I have sent the text (and another text
On Wed, 19 Apr 2006, Andre Engels wrote:
2006/4/18, Danny Yoo [EMAIL PROTECTED]:
H Can you send a link to the text that's causing performance
issues? It might be possible that someone here might isolate the
performance problem. (Hey, it happened before with BeautifulSoup...
*
i want to write a function which will sort the sentence by the length of
each word in the sentece, short length first.please help.
Hi Nywbon,
First: please do not reply to the whole email digest. The point of a
reply is to continue a previous
Hi All
I wanted to understand about OOPs Concept in Python in a easy way,
Please explain me with an example
I have been reading http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm
but at the moment still the concept is not clear
Thanks in Advance
Regards
Kaushal
Jan Eden wrote:
Hi,
is it correct that an object cannot be re-instantiated within it's __init__
method?
I tried:
class Omega:
def Display(self):
print self
class Alpha(Omega):
def __init__(self):
self = Beta()
class Beta(Omega):
Even though I am still new to python, I've recently had an insight as
to what makes OOP different from procedural programming.
Let's take perl for example. A variable in perl is like a bowl. It's an
empty vessel you can put things in. You can change the contents of
the bowl, you can empty the
On 4/19/06, Matthew White [EMAIL PROTECTED] wrote:
Even though I am still new to python, I've recently had an insight as
to what makes OOP different from procedural programming.
Let's take perl for example. A variable in perl is like a bowl. It's an
empty vessel you can put things in. You
class SOFileIndexRecord(object): def __init__(self, so): self._so=so def _get_code(self): return self._so.code def _set_code(self, value): self._so.code=value
testCode=property(_get_code, _set_code) # What does this do? def _get_fileName(self): return self._so.fileName def _set_fileName(self,
Thank you Michael, Danny and Alan for your suggestions.
I've included below my summary of the three very different
suggestions, my brief analysis of them, and my conclusion.
Anyone is free and welcome to comment!
On 4/18/06, Andre Roberge [EMAIL PROTECTED] wrote:
Hi all-
Suppose I had a
is it correct that an object cannot be re-instantiated within it's
__init__ method?
There are some tricks you can pull but the object is actually instantiated
before the init gets called. Really init is for initialisation of the
instance,
it's not a true constructor.
Background: I need to
class SOFileIndexRecord(object):
def __init__(self, so):
self._so=so
def _get_code(self):
return self._so.code
def _set_code(self, value):
self._so.code=value
testCode=property(_get_code, _set_code) # What does this do?
It says that testCode is a property
Ok,
If I can get it for free, I might as well go with say wxPython. Thanks
Yes, free as in beer, as in speech, and cross platform. Oh, and better
documented.
Hugo
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Hello,
I want to read a configuration file from a small python app (user preferences).
The .myapp.conf is in the home folder of the user.
if I do:
f=open(/home/user1/.myapp.conf,r) #it works
obviously I won't know the home user folder name then I wanted to use:
f=open(~/.myapp.conf,r) # but
os.getenv('HOME') will return the user's home directory as long as that
environment variable is set.
you can also use the pwd module:
pwd.getpwnam('mtw')
('mtw', 'x', 1000, 1000, ',,,', '/home/mtw', '/bin/bash')
-mtw
On Wed, Apr 19, 2006 at 07:55:14PM +0200, learner404 ([EMAIL PROTECTED])
f=open(~/.myapp.conf,r) # but it returns a IOError: [Errno 2] No such
file or directory:
How can I do to access this file whatever the user is ?
use os.path.expanduser(path)
http://www.python.org/doc/2.4.3/lib/module-os.path.html
hope this helps!
-- wesley
- - - - - - - - - - - - - - - -
I tried:
class Omega:
def Display(self):
print self
class Alpha(Omega):
def __init__(self):
self = Beta()
class Beta(Omega):
def __init__(self):
pass
objectus = Alpha()
objectus.Display()
which prints
__main__.Alpha instance at 0x54d50
It works great, thanks very much to the three of you for these light-speed answers ... I love this list !
Wesley, I've just pre-order your new edition Core Python programming on amazon France, it looks great. :)
Thanks
On 19/04/06, w chun [EMAIL PROTECTED] wrote:
f=open(~/.myapp.conf,r)# but
Hi,
You can use expanduser() from os.path for this:
import os.path
homedir = os.path.expanduser('~user1')
file_to_open = os.path.join(homedir, '.myapp.conf')
f = open(file_to_open, 'r')
Regards,
-Markus-
Quoting learner404 [EMAIL PROTECTED]:
Hello,
I want to read a configuration file
The .myapp.conf is in the home folder of the user.
...
obviously I won't know the home user folder name then I wanted to use:
How can I do to access this file whatever the user is ?
You can get the user name using getpass.getuser() as described in
the OS topic of my tutor under the Securiity
we are all happy to help. it is really good that you were able to get
it working so fast! also, if you want to do any kind of pattern
matching with * or ?, then check out the glob module.
merci! le livre does not look that good from here... it is a mess
and i have to clean it up before giving
If I can get it for free, I might as well go with say wxPython. Thanks
Yes, free as in beer, as in speech, and cross platform. Oh, and better
documented.
Sadly, you still pay for it in RAM usage :^)
Alan
___
Tutor maillist - Tutor@python.org
Hmm? How so? I'm using a whole lot of raw wxPython mixed with
Pythoncard for a project, and the entire process sits at 7Mb RAM usage
idle. WinXP btw.
Considering my small command line appns to start/stop Windows services
written in C use just over 1Mb, 7Mb isn't overly bad.
The other good thing
I think I'm going to have to suck it up and learn some regular expressions.
I have finally gotten my script (using the excellent pyserial module)
to behave. Most of my troubles as enumerated here before were utterly
self-induced. Apparently one cannot watch the execution of one's script
through
Hi Doug,
Best tip ever is your_python_dir\tools\scripts\redemo.py
Interactive regexes. :)
This is pretty good as well - http://www.amk.ca/python/howto/regex/
Good luck,
Liam Clarke
On 4/20/06, doug shawhan [EMAIL PROTECTED] wrote:
I think I'm going to have to suck it up and learn some
Hi,
The categories of calls under this drop down box, are they going to
increase anytime soon, or shall I go with what's there?
Regards,
Liam Clarke
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
How can I do to access this file whatever the user is ?
use os.path.expanduser(path)
Neat Wesley, I've never noticed that one before.
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I cannot for the life of me figure out a pythonic way (read: using the
split() builtin) to scan for instances of these characters in such and
such
order and proximity. I know this is what regex is for,
I'm afraid so, it looks like the time has come to import re.
I have obtained a copy of
Greetings:
I am writing a function that accepts a string of decimal digits, calculates a
checksum and returns it as a single character string.
The first step in the calculation is to split the input into two strings: the
even- and odd- numbered digits, respectively. The least significant
On 20/04/06, Carroll, Barry [EMAIL PROTECTED] wrote:
The following code fragment does the job but seems sort of brutish and
inelegant to me:
s = '987654321'
odd = ''
for c in s[::-2]:
... odd = c + odd
...
String slicing will actually produce strings :-)
eg:
s = '987654321'
Terry Carroll wrote:
How can I tell if a .pyc file was built with 2.3 or 2.4?
There's a Magic Number in the first 2 or 4 bytes, (depending on whether
you consider the \r\n part of the MN).
f = open(pycfile.pyc, rb)
magictable = {'\x3b\xf2\r\n': 2.3, '\x6d\xf2\r\n' : 2.4}
magic =
Don Taylor wrote:
Finally, are there any other possible file extension types that I should
be looking at?
.pyo is like a .pyc but compiled with optimizations on.
Kent
___
Tutor maillist - Tutor@python.org
Hi all, I do apologise for this,
This was an email that has nothing to do with Python or the tutor
list, so my apologies to all. Somehow I managed to send it to the
wrong recepient.
(And my thanks to Bob for being brave enough to attempt to answer what
would be a hopelessly vague question. :-) )
34 matches
Mail list logo