I wrote a simple calculator script:
#!/usr/bin/python env
def calculator(n1, operator, n2):
f1 = float(n1)
f2 = float(n2)
if operator == '+':
return f1 + f2
elif operator == '-':
return f1 - f2
elif operator == '*':
return f1 * f2
elif operator == '
Thanks, everyone, for your help.
It was a pretty narrow question because it's a pretty specific task, but
only because I was guessing there was more than one way of shelling an
acorn. My original idea was something a lot like:
lst = []
chars = '@*&^$&[EMAIL PROTECTED](&@$*(&[EMAIL PROTECTED](*&*
Hello friends,
I wanted a link or tutorial to help me understand how to read or write
ascii text file in python. with and without using Numpy. If you have any
example that would also help me understand better.
thanks,
Varsha Purohit,
Graduate Student
John Fouhy wrote:
> On 18/09/2007, Andrew Nelsen <[EMAIL PROTECTED]> wrote:
>
>> I was wondering, recently, the most expedient way to take a string with
>> [EMAIL PROTECTED]&*] and alpha-numeric characters [ie. "[EMAIL
>> PROTECTED]@*$g@)$&^@&^$F"] and
>> place all of the letters in a string or
Andrew Nelsen wrote:
> I was wondering, recently, the most expedient way to take a string with
> [EMAIL PROTECTED]&*] and alpha-numeric characters [ie. "[EMAIL
> PROTECTED]@*$g@)$&^@&^$F"] and
> place all of the letters in a string or list.
Another way to do this is to use str.translate(). This
On 18/09/2007, Andrew Nelsen <[EMAIL PROTECTED]> wrote:
> I was wondering, recently, the most expedient way to take a string with
> [EMAIL PROTECTED]&*] and alpha-numeric characters [ie. "[EMAIL
> PROTECTED]@*$g@)$&^@&^$F"] and
> place all of the letters in a string or list. I thought there could
Man...really not my night:
import re
def getLettersOnly( chars ) :
pat = re.compile('[a-zA-Z]')
return ''.join(pat.findall(chars))
if __name__ == "__main__":
print getLettersOnly("afdlkjal32jro3kjlkj(*&&^%&^TUHKLJDHFKJHS(*&987")
Which would produce:
afdlkjaljrokjlkjTUHKLJDHFKJH
This seems to work to get out the alpha-numeric characters.
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
import re
pat = re.compile('\w')
lst = []
chars = '@*1&^$&[EMAIL PROTECTED](&@2$*(&[EMAIL PROTECTED](*&3*(&c^&%4&^%'
lst = pat.findall(chars)
for x in lst:
print x,
--
Thank
On Mon, Sep 17, 2007 at 07:48:56PM -0400, Michael Langford wrote:
>
>Not my night...the second sentence "To get the set of letters, use"
>should read "To get the filtered string".time for more Coke Zero.
> --Michael
>On 9/17/07, Andrew Nelsen <[6] [EMAIL PROTECTED]> wrot
Not my night...the second sentence "To get the set of letters, use" should
read "To get the filtered string".time for more Coke Zero.
--Michael
--
Michael Langford
Phone: 404-386-0495
Consulting: http://www.TierOneDesign.com/
Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.c
At first I totally misread this
To get the set of letters, use
import string
string.ascii_letters
Then do what you said in your algorithm.
A shorthand way to do that is
filteredString = ''.join([c for c in foo if c in string.ascii_letters])
--
Michael Langford
Phone: 404-386-0495
Consult
On Mon, Sep 17, 2007 at 07:21:09PM -0400, Andrew Nelsen wrote:
>
>I was wondering, recently, the most expedient way to take a string
>with [EMAIL PROTECTED]&*] and alpha-numeric characters [ie.
>"[EMAIL PROTECTED]@*$g@)$&^@&^$F"] and place all of the letters in a
> string or
>list
I was wondering, recently, the most expedient way to take a string with
[EMAIL PROTECTED]&*] and alpha-numeric characters [ie. "[EMAIL
PROTECTED]@*$g@)$&^@&^$F"] and
place all of the letters in a string or list. I thought there could be
obvious ways:
A) Find all the letters, put them in a list, o
Eric Lake wrote:
> I am still trying to understand when to use a class and when not to. All
> of the coding that I have done in the past (Python, Perl) has been
> procedural / functional. I would really like to do more OOP but I am not
> really sure when I need it.
My take on that question is here
"chinni" <[EMAIL PROTECTED]> wrote
> Which Book is better for python parsing and reading Xml files from
> local
> machine and remote machine and also through http...
A lot depends on which parser you are using.
David Metz "Text Processing in Python" is a good general text
on parsing, including
"Eric Lake" <[EMAIL PROTECTED]> wrote
> I am still trying to understand when to use a class and when not to.
> All
> of the coding that I have done in the past (Python, Perl) has been
> procedural / functional. I would really like to do more OOP but I am
> not
> really sure when I need it.
You
"Eric Abrahamsen" <[EMAIL PROTECTED]> wrote
> to do it. I was thinking of cleaner ways of giving an instance a
> 'name' attribute than
>
> instance_name = Class('instance_name')
The thing is that you shouldn't even try!
The object can have a name and that name will be constant
regardless of which
Short sections of code are not where classes shine.
Classes become much more valuable when you start to get a lot of hairy
details you need to pass around. For your code, for instance, you could pass
in the whole registry key you want, and have out pop a RegKey object.
This would be say, usable i
I am still trying to understand when to use a class and when not to. All
of the coding that I have done in the past (Python, Perl) has been
procedural / functional. I would really like to do more OOP but I am not
really sure when I need it.
I have the following code. Is there any way that it would
> This is pretty hard. For one thing, the object will not be bound to
> a name until after __init__() is finished.
Ah, that's a good thing to know...
> you could probably use the stack frame to find the point of call
> and inspect the byte codes there to find the name...
I was afraid the ans
Eric Abrahamsen wrote:
> When instantiating a class, is it possible for that instance to
> 'know' (via the __init__ method, I suppose) the name of the variable
> it's been assigned to?
This is pretty hard. For one thing, the object will not be bound to a
name until after __init__() is finishe
On Sep 17, 2007, at 7:21 PM, Alan Gauld wrote:
>
> "Eric Abrahamsen" <[EMAIL PROTECTED]> wrote
>
>> When instantiating a class, is it possible for that instance to
>> 'know' (via the __init__ method, I suppose) the name of the variable
>> it's been assigned to?
>
>
> Presumably you have a reason
I've found Python Cookbook to be a good, modern resource for parsing as well
as tricks for remote pages.
Link at amazon: *http://tinyurl.com/2njsd9
--Michael
Original url:
http://www.amazon.com/gp/product/0596007973/102-1641864-7294551?ie=UTF8&tag=rowlab-20&linkCode=xm2&camp=1789&creati
"Eric Abrahamsen" <[EMAIL PROTECTED]> wrote
> When instantiating a class, is it possible for that instance to
> 'know' (via the __init__ method, I suppose) the name of the variable
> it's been assigned to?
You could pass it in as a string but there is little point.
Recall that in Python variable
Hi all,
Which Book is better for python parsing and reading Xml files from local
machine and remote machine and also through http...
Can any one Please Post the link at least ...waiting for u r Replies .
Thanku:)
--
Cheers,
M.Srikanth Kumar,
Phone no: +91-9866774007
When instantiating a class, is it possible for that instance to
'know' (via the __init__ method, I suppose) the name of the variable
it's been assigned to?
Thanks
E
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Carlos Daniel Ruvalcaba Valenzuela wrote:
> Don't worry too much for the accessors, I'm pretty sure it won't
> degrade your performance in a noticeable way, you objects will only
> grow a tiny bit by adding a function to the class, all objects share
> the same in memory code and each one has it's o
"Jeff Peery" <[EMAIL PROTECTED]> wrote
> I am taking measurements and building up a list of objects
> for each measurement. the class I created for the objects has
> attributes
> I also have functions within my class (I think they are properly
> named 'accessors'?) that get a piece of data within
"Ara Kooser" <[EMAIL PROTECTED]> wrote
> Is the translation for the above line of code into pseudocode?
> yeast for every yeast in the list yeasts if the yeast method
> returned isAlive()
Others have given you the solution.
But note that you still have the terminology wrong.
"... the yeast meth
王超 wrote:
> yes, but I mean if I have the line like this:
>
> line = """38166 us::Video_Cat::Other; us::Video_Cat::Today Show;
> us::VC_Supplier::bc; 1002::ms://bc.wd.net/a275/video/tdy_is.asf;
> 1003::ms://bc.wd.net/a275/video/tdy_is_.fl;"""
>
> I want to get the part "us::MSNVideo_Cat::Other;
Kent,
Thanks this is exactly the solution I am looking for... so simple.
On 9/15/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
>
> John wrote:
> > #Set up writer
> > import csv
> > vardict=vars()
> > for var in vardict:
> > if var=='allcum' or var==
31 matches
Mail list logo