Newbie question

  • Thread starter Bruno Desthuilliers
  • Start date
B

Bruno Desthuilliers

(e-mail address removed) a écrit :
Yes, I want specific characters in specific positions.
Err... Sorry, but something is not clear here. When you say "strip out",
you mean "get rid of", or "access to" ? For what I remember of basic,
I guess it's the second answer, so:
>>> fname = "AVC1030708.14"
>>> print fname[0] A
>>> print fname[-1] 4
>>> print fname[2:4] C1
>>> print fname[2:-4] C103070
>>>

etc...

Also and while we're at it, you also have:
>>> fname.split('.') ['AVC1030708', '14']
>>> fname.split('.')[0] 'AVC1030708'
>>> fname.split('.')[1] '14'
>>> fname.strip('4') 'AVC1030708.1'
>>> fname.strip('A') 'VC1030708.14'
>>> fname.lstrip('A') 'VC1030708.14'
>>> fname.rstrip('4') 'AVC1030708.1'
>>> fname.rstrip('41.')
'AVC1030708'

etc...

HTH
 
K

koutoo

If I have a file name: AVC1030708.14. How do I strip out certain
characters from the file name? I am so used to using MID, LEFT, and
RIGHT functions, that I have no idea how to do this in python? I have
had trouble as well with most newbies on finding the help. But I have
used the command line built in help, but with no luck. Thanks.

Kou
 
S

Shawn Milochik

If I have a file name: AVC1030708.14. How do I strip out certain
characters from the file name? I am so used to using MID, LEFT, and
RIGHT functions, that I have no idea how to do this in python? I have
had trouble as well with most newbies on finding the help. But I have
used the command line built in help, but with no luck. Thanks.

Kou


Do you want to strip out specific characters, characters in specific
positions, or characters matching certain patterns?
 
K

koutoo

Do you want to strip out specific characters, characters in specific
positions, or characters matching certain patterns?

Yes, I want specific characters in specific positions.
 
K

koutoo

Yes, I want specific characters in specific positions.

Try this:

newString = oldString[0:3] + oldString[5:10]

Some other quick examples:
test = "this is a test"
test 'this is a test'
fred = test[:3] + test[9:]
fred 'thi test'
test[0:5] 'this '
test[:5] 'this '
test[4:]

' is a test'- Hide quoted text -

- Show quoted text -

I see. It's so hard to imagine the world of python than from VB.
It's like looking at VB is in 2 dimensions, where with Python, it's
more 3D. The code is so simple, yet it's hard for me to envision how
to do something so simple. I guess it's because the rules or the way
of looking at things in Python, things can be stripped down to the
bare bones and in so many ways. Thanks.

Kou
 
F

Francesco Guerrieri

If I have a file name: AVC1030708.14. How do I strip out certain
characters from the file name? I am so used to using MID, LEFT, and
RIGHT functions, that I have no idea how to do this in python? I have
had trouble as well with most newbies on finding the help. But I have
used the command line built in help, but with no luck. Thanks.

Kou

As a newbie, you would do well to read and study the tutorial which
you can find at http://docs.python.org/tut/tut.html

In particular there is an interesting section on Strings:
http://docs.python.org/tut/node5.html#SECTION005120000000000000000

and
http://docs.python.org/lib/string-methods.html

Francesco
 
L

Laurent Pointal

If I have a file name: AVC1030708.14. How do I strip out certain
characters from the file name? I am so used to using MID, LEFT, and
RIGHT functions, that I have no idea how to do this in python? I have
had trouble as well with most newbies on finding the help. But I have
used the command line built in help, but with no luck. Thanks.

Kou

As you seem to know about mid, left, right functions, you may have already
programmed with languages such as Basic.

Learning Python is usually easy, see Python tutorials in several places:
* http://docs.python.org/tut/tut.html
* http://www.awaretek.com/tutorials.html
* http://effbot.org/pytut/


Once you have the language basics, you can look after the standard library
documentation:
* http://docs.python.org/lib/lib.html

For a very quick overview of the language and the libraries, you may take a
look at R.Gruet Python Quick Reference or at my Python Quick Reference
Card - these are refs, not learning tools.
* http://rgruet.free.fr/
* http://www.limsi.fr/Individu/pointal/python/pqrc/ (still for Python 2.4 -
working on 2.5)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top