a class variable question

2006-06-28 Thread micklee74
hi
i have define a class like this

class A:
 _var1 = 0
 def __init__(self):
 ## some initialization
 self.func1()

 def func1():
  .
 _var1 = 1
 

 def getvarValue(self):
 return _var1
I wanted var1 to be global inside Class A.
when i do

AnInstance = A()
AnInstance.getvarValue()

it gives me 0. It should be 1.  What am i doing wrong here..thanks

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


automatic debugger?

2006-06-26 Thread micklee74
hi
is there something like an automatic debugger module available in
python? Say if i enable this auto debugger, it is able to run thru the
whole python program, print variable values at each point, or print
calls to functions..etc...just like the pdb module, but now it's
automatic.
thanks

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


MSoffice metadata

2006-06-24 Thread micklee74
hi
is there a module in Python to extract metadata in MS office documents
thanks

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


mapping None values to ''

2006-06-18 Thread micklee74
hi
i wish to map None or None values to .
eg
a = None
b = None
c = None

map( something  ,  [i for i in [a,b,c] if i in (None,None) ])

I can't seem to find a way to put all values to . Can anyone help?
thanks

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


a string problem

2006-06-13 Thread micklee74
hi

if i have a some lines  like this
a ) here is first string
b ) here is string2
c ) here is string3

When i specify i only want to print the lines that contains string ie
the first line and not the others. If i use re module, how to compile
the expression to do this? I tried the re module and using simple
search() and everytime it gives me all the 3 lines that have string
in it, whereas i only need line 1.
If re module is not needed, how can i use string manipulation to do
this? thanks

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


Re: a string problem

2006-06-13 Thread micklee74

John Salerno wrote:

 [EMAIL PROTECTED] wrote:
  hi
 
  if i have a some lines  like this
  a ) here is first string
  b ) here is string2
  c ) here is string3
 
  When i specify i only want to print the lines that contains string ie
  the first line and not the others. If i use re module, how to compile
  the expression to do this? I tried the re module and using simple
  search() and everytime it gives me all the 3 lines that have string
  in it, whereas i only need line 1.
  If re module is not needed, how can i use string manipulation to do
  this? thanks
 

 As far as re goes, you can search for the pattern '\bstring\b', which
 will find just the word 'string' itself. Not sure if there's a better
 way to do it with REs.

 And I'm actually ashamed to admit that I know the RE way, but not the
 regular string manipulation way, if there is one! This seems like
 something easy enough to do without REs though.

thanks !

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


Re: a string problem

2006-06-13 Thread micklee74

John Salerno wrote:

 [EMAIL PROTECTED] wrote:
  hi
 
  if i have a some lines  like this
  a ) here is first string
  b ) here is string2
  c ) here is string3
 
  When i specify i only want to print the lines that contains string ie
  the first line and not the others. If i use re module, how to compile
  the expression to do this? I tried the re module and using simple
  search() and everytime it gives me all the 3 lines that have string
  in it, whereas i only need line 1.
  If re module is not needed, how can i use string manipulation to do
  this? thanks
 

 As far as re goes, you can search for the pattern '\bstring\b', which
 will find just the word 'string' itself. Not sure if there's a better
 way to do it with REs.

 And I'm actually ashamed to admit that I know the RE way, but not the
 regular string manipulation way, if there is one! This seems like
 something easy enough to do without REs though.

if RE has the \b and it works, can we look into the source of re and
see how its done for \b ?

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


Re: a string problem

2006-06-13 Thread micklee74

John Salerno wrote:

 [EMAIL PROTECTED] wrote:
  hi
 
  if i have a some lines  like this
  a ) here is first string
  b ) here is string2
  c ) here is string3
 
  When i specify i only want to print the lines that contains string ie
  the first line and not the others. If i use re module, how to compile
  the expression to do this? I tried the re module and using simple
  search() and everytime it gives me all the 3 lines that have string
  in it, whereas i only need line 1.
  If re module is not needed, how can i use string manipulation to do
  this? thanks
 

 As far as re goes, you can search for the pattern '\bstring\b', which
 will find just the word 'string' itself. Not sure if there's a better
 way to do it with REs.

 And I'm actually ashamed to admit that I know the RE way, but not the
 regular string manipulation way, if there is one! This seems like
 something easy enough to do without REs though.

just curious , if RE has the \b and it works, can we look into the
source of re and see how its done for \b ?

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


Re: a string problem

2006-06-13 Thread micklee74

John Salerno wrote:
 [EMAIL PROTECTED] wrote:

  just curious , if RE has the \b and it works, can we look into the
  source of re and see how its done for \b ?

 I had a look in the sre module (which re seems to import), but I
 couldn't find much. I'm not the best at analyzing source code, though. :)

 What is it you want to know about \b? It searches for the empty string
 before and after a word (word being an alphanumeric character that can
 include underscores).

 A little more specific info is in the docs:

 Matches the empty string, but only at the beginning or end of a word. A
 word is defined as a sequence of alphanumeric or underscore characters,
 so the end of a word is indicated by whitespace or a non-alphanumeric,
 non-underscore character. Note that \b is defined as the boundary
 between \w and \ W, so the precise set of characters deemed to be
 alphanumeric depends on the values of the UNICODE and LOCALE flags.
 Inside a character range, \b represents the backspace character, for
 compatibility with Python's string literals.

thanks..actually i had seen \b in the docs before, just that it slipped
my mind when i was doing the coding. was even meddling with look aheads
..which is not the answer anyway.
well, since re has the \b, was wondering why there is no implementation
of it in strings. So the idea of looking at the source or re on how
it's done came to my mine..i suppose we have to go down to viewing the
C source then..:-)

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


proper way to use popen4

2006-06-13 Thread micklee74
hi
i have to execute some SQL statements against a database using a SQL
client
i want to use the os.popen4 module
can someone correct the way i use os.popen4?
thanks

fin = select * from some_table #sql statement
client = osql server user password #sql client syntax
fin, fout = os.popen4(client)
fin.close()  --- i need to close the stdin first right?
print fout.read()

I get no results when i did the above...
thanks

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


regexp questoin

2006-06-09 Thread micklee74
hi

i created a script to ask user for an input that can be a pattern
right now, i use re to compile that pattern
pat = re.compile(r%s %(userinput) )  #userinput is passed from
command line argument
if the user key in a pattern , eg [-] ,  and my script will search some
lines that contains [-]

pat.findall(lines)

but the script produce some error: sre_constants.error: unexpected end
of regular expression

how can i successful catch  patterns such as [-] in my regexp
compilation where input is unknown...?
thanks

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


Re: regexp questoin

2006-06-09 Thread micklee74

Fredrik Lundh wrote:
 [EMAIL PROTECTED] wrote:

   pat = re.compile(r%s %(userinput) )  #userinput is passed from
   command line argument

 that r%s % (userinput) thing is a pointless operation: the r prefix
 controls how backslashes in a string literal is parsed; the result is an
 ordinary string (%s in this case).

 in other words,

 pat = re.compile(r%s % (userinput))

 is just a slightly convoluted way to write

 pat = re.compile(str(userinput))

 and since you know that userinput is a string (at least if you got it
 from sys.argv), you might as well write

 pat = re.compile(userinput)

  if the user key in a pattern , eg [-] ,  and my script will search some
  lines that contains [-]
 
  pat.findall(lines)
 
  but the script produce some error: sre_constants.error: unexpected end
  of regular expression

 for what pattern?  [-] is a valid regular expression (it matches a
 single minus), but e.g. [- is invalid.  to deal with this, catch the
 exception:

 try:
pat = re.compile(userinput)
 except re.error:
print invalid regular expression:, userinput
sys.exit()

 hope this helps!

 /F


hi. thanks for all the help.
actually, i am doing an application that allows user to delete files by
entering an input pattern. so if he has files that have special
characters such as [-] or others, then i want to filter them off 
the solution for re.compile(re.escape(userinput)) might work, i have to
give it a try.
thanks again.

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


printing backslash

2006-06-07 Thread micklee74
hi
i want to print something like this

|\|

first i tried it as string

a = |\|

it prints ok

but when i put it to a list

a = [|\|]

it gives me '|\\|' .there are 2 back slashes...i only want one.. how
can i properly escape it?
I have tried [r|\|] , [r'\\'] but they do not work...
thanks

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


printing backslash

2006-06-07 Thread micklee74
hi
how can i sucessfully print  |\|  in the output of a print command

a = |\|
print a

but it gives me |\\|

i tried raw strings too, but it doesn't print |\| . It prints |\\|
instead

eventually, i also want |\| to be inside a list:
alist = [|\|, 'blah', 'blah'] . How can i put |\| inside a list?

can someone show me how it can be done?
thanks

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


Re: printing backslash

2006-06-07 Thread micklee74

Tim Chase wrote:

  i want to print something like this
 
  |\|
 
  first i tried it as string
 
  a = |\|
 
  it prints ok
 
  but when i put it to a list
 
  a = [|\|]
 
  it gives me '|\\|' .there are 2 back slashes...i only want one.. how
  can i properly escape it?
  I have tried [r|\|] , [r'\\'] but they do not work...

 You omit how you're printing matters.

   s1 = '|\|'
   s2 = r'|\|'
   s3 = '|\\|'
   print repr(s1), '-', s1
 '|\\|' - |\|
   print repr(s2), '-', s2
 '|\\|' - |\|
   print repr(s3), '-', s3
 '|\\|' - |\|

 There's a difference between the repr() of a string (which
 escapes items that need to be escaped) and printing items.  All
 three *print* the item as you request it.  All three represent
 the item with the proper backslashes.

 The preferred form of putting backslashes in a string is the s2
 or s3 form, as the s1 form can have some unpredictable(*) results:

 \| happens not to be a recognized escape sequence
 \t is, so you get things like
s = '\t\|'
s
   '\t\\|'
 -tkc

 (*) unpredictable defined as, predictable, if you happen to
 have memorized the exact set of characters that do or don't need
 to beescaped

thanks, i got  it

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


check for dictionary keys

2006-06-02 Thread micklee74
hi
in my code, i use dict(a) to make to a into a dictionary , a comes
from user input, so my program does not know in the first place. Then
say , it becomes

a = { '-A' : 'value1' , '-B' : value2 , -C : value3 , '-D' :
'value4' }

somewhere next in my code, i will check for these..:

1)  -A and -B cannot exist together
2) -A and -C cannot exist together
3) -A and -B and -D cannot exist together
4) and lots of other combinations to check for

how can i efficiently check for the above? At first as i do simple
checks , i use if and else.
But as i began to check for more combinatoiuns, it gets messy

thanks.

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


default argument values qns

2006-06-01 Thread micklee74
hi
i have declared a function like this:

def aFunction ( arg1 , arg2 = 0):
 
 print type(arg2)

when i try to print the type of arg2, it gives me 'str' type..why is it
not integer type, since i have
declared it as 0 ??
thanks

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


deleting texts between patterns

2006-05-12 Thread micklee74
hi
say i have a text file

line1
line2
line3
line4
line5
line6
abc
line8 ---to be delete
line9  ---to be delete
line10  ---to be delete
line11  ---to be delete
line12  ---to be delete
line13 ---to be delete
xyz
line15
line16
line17
line18

I wish to delete lines that are in between 'abc' and 'xyz' and print
the rest of the lines. Which is the best way to do it? Should i get
everything into a list, get the index of abc and xyz, then pop the
elements out? or any other better methods? 
thanks

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


find all index positions

2006-05-11 Thread micklee74
hi
say i have string like this
astring = 'abcd efgd 1234 fsdf gfds abcde 1234'
if i want to find which postion is 1234, how can i achieve this...? i
want to use index() but it only give me the first occurence. I want to
know the positions of both 1234
thanks

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


printing out elements in list

2006-05-08 Thread micklee74
hi

i have a list with contents like this
alist = ['QWER' , 'askfhs', 'REWR' ,'sfsdf' , 'FGDG',
'sdfsdgffdgfdg' ]

how can i convert this list into a dictionary such that

dictionary = { 'QWER':'askfhs' , 'REWR' : 'sfsdf' , 'FGDG',
'sdfsdgffdgfdg' }

thanks

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


Re: printing out elements in list

2006-05-08 Thread micklee74
thanks for all your replies...I will go test them out..
I was wondering what does this mean alist[1::2]?
thanks

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


Re: printing out elements in list

2006-05-08 Thread micklee74
thanks for the detailed explaination... i know about basic lists
slicing..just havn't seen one with steps yet..
thanks again...clp rocks.

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


pythonic way to sort

2006-05-03 Thread micklee74
hi
I have a file with columns delimited by '~' like this:

1SOME STRING  ~ABC~12311232432D~20060401~
2SOME STRING  ~DEF~13534534543C~20060401~
3SOME STRING  ~ACD~14353453554G~20060401~

.

What is the pythonic way to sort this type of structured text file?
Say i want to sort by 2nd column , ie ABC, ACD,DEF ? so that it becomes

1SOME STRING  ~ABC~12311232432D~20060401~
3SOME STRING  ~ACD~14353453554G~20060401~
2SOME STRING  ~DEF~13534534543C~20060401~
?
I know for a start, that i have to split on '~', then append all the
second columns into a list, then sort the list using sort(), but i am
stuck with how to get the rest of the corresponding columns after the
sort

thanks...

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


stripping

2006-05-02 Thread micklee74
hi
i have a file test.dat eg

abcdefgh
ijklmn
 -newline
opqrs
tuvwxyz
  ---newline


I wish to print the contents of the file such that it appears:
abcdefgh
ijklmn
opqrs
tuvwxyz

here is what i did:
f = open(test.dat)
while 1:
line = f.readline().rstrip(\n)
if line == '':
break
#if not re.findall(r'^$',line):
print line

but it always give me first 2 lines, ie
abcdefgh
ijklmn

What can i do to make it print all..?
thanks

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


stripping blanks

2006-05-02 Thread micklee74
hi
i have a file test.dat eg

abcdefgh
ijklmn
 -newline
opqrs
tuvwxyz
  ---newline

I wish to print the contents of the file such that it appears:
abcdefgh
ijklmn
opqrs
tuvwxyz

here is what i did:
f = open(test.dat)
while 1:
line = f.readline().rstrip(\n)
if line == '':
break
#if not re.findall(r'^$',line):
print line

but it always give me first 2 lines, ie
abcdefgh
ijklmn

What can i do to make it print all..?
thanks

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


strip newlines and blanks

2006-05-02 Thread micklee74
hi
i have a file test.dat eg

abcdefgh
ijklmn
 -newline
opqrs
tuvwxyz


I wish to print the contents of the file such that it appears:
abcdefgh
ijklmn
opqrs
tuvwxyz

here is what i did:
f = open(test.dat)
while 1:
line = f.readline().rstrip(\n)
if line == '':
break
print line

but it always give me first 2 lines, ie
abcdefgh
ijklmn

What can i do to make it print all w/o the newlines..? and what is the
proper way to skip printing blank lines while iterating file contents?

thanks

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


blank lines representation in python

2006-05-02 Thread micklee74
hi
what is the correct way to represent blank lines in python (while
iterating a file) without regexp? I know one way is to use
re.search((line,r'^$') to grab a blank line, but i wanna try not to use
regexp...
is it
1) if line == '': dosomething()  (this also means EOF right? )
2) if line is None: dosomething()
3) if not line: dosomething()
thanks

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


Re: strip newlines and blanks

2006-05-02 Thread micklee74
thanks..and sorry, i am using the web version of google groups and
didn't find  an option i can edit my post, so i just removed it..
thanks again for the reply..

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


can anyone advise me

2006-04-27 Thread micklee74
why the output of this code :
x = 0
while x  10:
z = 0
print x
x = x + 1
while z  x:
print z,
z = z + 1

is

0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9  ---extra


instead of :
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9

thanks

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


Re: can anyone advise me

2006-04-27 Thread micklee74

Dan Sommers wrote:
 On 27 Apr 2006 02:48:46 -0700,
 [EMAIL PROTECTED] wrote:

  why the output of this code :
  x = 0
  while x  10:
  z = 0
  print x
  x = x + 1
  while z  x:
  print z,
  z = z + 1

  is

  0

 Okay, that was x, from the print statement inside the x-loop.

  0 1

 And that's z, from the print statement inside the z-loop.  z is 0, and
 then when z is 1, it's not less than x, so we're done printing z's.

 And then we get the next x.

  0 1 2

 And two more z's, 0 and 1, since x is now 2.

 And another x.

 Since this might be homework, I'll stop at a hint:  you need to think
 about when you want each printed line to end, and make sure that you
 tell python to end it there.

 Regards,
 Dan

 --
 Dan Sommers
 http://www.tombstonezero.net/dan/
 I wish people would die in alphabetical order. -- My wife, the genealogist


thanks..solved...just removed the print x..

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


Re: python pyc or pyo files

2006-04-20 Thread micklee74
thanks! got it

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


a subprocess qns

2006-04-20 Thread micklee74
hi
i wanted to start execute a command and put it in the background. i am
using Unix.
Usually i start this command using something like this :
/path/somecmd   with the  to put it to background.
i looked at the subprocess module docs and came across this statement
Replacing os.spawn*
---
P_NOWAIT example:
pid = os.spawnlp(os.P_NOWAIT, /bin/mycmd, mycmd, myarg)
==
pid = Popen([/bin/mycmd, myarg]).pid


Can i ask if P_NOWAIT means the same as  ?? so if it is, then  this
statement
pid = os.spawnlp(os.P_NOWAIT, /bin/mycmd, mycmd, myarg)

will put mycmd into background and return to the caller...?

thanks

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


python pyc or pyo files

2006-04-19 Thread micklee74
hi

any good websites or articles that describes about pyc or pyo files ,
how they are generated and what's the difference between them and
Java's bytecode?? 
thanks

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


Re: python pyc or pyo files

2006-04-19 Thread micklee74
thanks !
can i ask again...
I have two scripts , A.py and B.py
In B.py,  i have an import statement to import A.py
When i executed B.py, i saw a A.pyc in the same directory, but not
B.pyc 
This is an expected behaviour right? why is B.pyc not generated?

thanks

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


any update to this?

2006-04-16 Thread micklee74
hi
i was looking at this :
http://www.python.org/doc/essays/comparisons.html
on comparisons of python and other languages? are there any updates to
this doc? or is there
other reliable source for such comparison elsewhere? thanks

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


nested functions

2006-04-14 Thread micklee74
hi
just curious , if i have a code like this?

def a():
  def b():
print b
  def c():
print c

how can i call c() ??

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