Mailing List Archive

Beginner in Python
Hi,

I wanted to start programming in python today and had some problems.
I wrote the famous "Hello, world"-programm and saved it as
helloworld.py. If I open the programm directly in the explorer it works
but I cannot start it from Ms-Dos. If I type python helloworld.py I get
the message:

File "<stdin>", line 1
python helloworld.py
^

SyntayError: invalid syntax

What is my mistak? Can anyone help me?

Thank you,

Christian

--
Don't panic.

ICQ 116707729
Beginner in Python [ In reply to ]
On Tuesday 06 November 2001 14:02, Christian Schnell wrote:

> File "<stdin>", line 1
> python helloworld.py
> ^
>
> SyntayError: invalid syntax
>

You are apparently trying to type this line at the Python prompt. Do not do
this. At the MSDOS _command_ prompt ( e.g. c:\> ), type

python helloworld.py

By the way, when pasting error messages, try to avoid editing them as this
obscures the message (since you are new to Python, you might not realize the
importance of something you are deleting - in this case you deleted the ">>>"
python prompt which would be an obvious indicator to someone reading it that
you were doing this in the Python interactive interpreter).


--
Cliff Wells
Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308
(800) 735-0555 x308
Beginner in Python [ In reply to ]
Hah... I got caught explaining this one last week. ;-)

You are to type "python helloworld.py" at the dos prompt
("C:\Dir\Of\HelloWorld>"), not the python prompt (">>>"). I suspect that as
double click it in the explorer that everything else required is already in
place.

--

Emile van Sebille
emile@fenx.com

---------
"Christian Schnell" <schrist@gmx.net> wrote in message
news:3BE85DF9.CDF844D2@gmx.net...
> Hi,
>
> I wanted to start programming in python today and had some problems.
> I wrote the famous "Hello, world"-programm and saved it as
> helloworld.py. If I open the programm directly in the explorer it works
> but I cannot start it from Ms-Dos. If I type python helloworld.py I get
> the message:
>
> File "<stdin>", line 1
> python helloworld.py
> ^
>
> SyntayError: invalid syntax
>
> What is my mistak? Can anyone help me?
>
> Thank you,
>
> Christian
>
> --
> Don't panic.
>
> ICQ 116707729
>
>
Beginner in Python [ In reply to ]
Hi,

thank you. This was my mistake. I also tried it at the dos promptyesterday, but
I worked in the wrong directory.

Thanks,

Christian


Emile van Sebille schrieb:

> Hah... I got caught explaining this one last week. ;-)
>
> You are to type "python helloworld.py" at the dos prompt
> ("C:\Dir\Of\HelloWorld>"), not the python prompt (">>>"). I suspect that as
> double click it in the explorer that everything else required is already in
> place.
>
> --
>
> Emile van Sebille
> emile@fenx.com
>
> ---------
> "Christian Schnell" <schrist@gmx.net> wrote in message
> news:3BE85DF9.CDF844D2@gmx.net...
> > Hi,
> >
> > I wanted to start programming in python today and had some problems.
> > I wrote the famous "Hello, world"-programm and saved it as
> > helloworld.py. If I open the programm directly in the explorer it works
> > but I cannot start it from Ms-Dos. If I type python helloworld.py I get
> > the message:
> >
> > File "<stdin>", line 1
> > python helloworld.py
> > ^
> >
> > SyntayError: invalid syntax
> >
> > What is my mistak? Can anyone help me?
> >
> > Thank you,
> >
> > Christian
> >
> > --
> > Don't panic.
> >
> > ICQ 116707729
> >
> >

--
Don't panic.

ICQ 116707729
Re: beginner in python [ In reply to ]
Beema shafreen wrote:
> hi everybody,
> I am beginner in python
> I have to calculate the euclidean distance between the atoms from a pdb
> file
> i have written the the code and its shows me some error ,
> the code:
> import re
> import string
> import math
> ab =[]
> x_value = []
> y_value = []
> z_value = []
> fh = open("1K5N.pdb",'r')
> for atom in fh.readlines():
> a = atom.strip()
> pattern= re.compile('^ATOM.*')
> atom_file= pattern.search(a)
> if atom_file:
> atom_data = atom_file.group()
> x_coordinate = atom_data[31:38]
> y_coordinate = atom_data[39:46]
> z_coordinate = atom_data[47:54]
> x_value.append(x_coordinate)
> y_value.append(y_coordinate)
> z_value.append(z_coordinate)
> for x in range(len(x_value)):
> x_co = float(x_value[x])-float(x_value[x+1])
> y_co = float(y_value[x])-float(y_value[x+1])
> z_co = float(z_value[x])-float(z_value[x+1])
> data = math.sqrt(x_co)*(x_co)+(y_co)*(y_co)+(z_co)*(z_co)
> print data
> ~
> and the error ,message
> File "pdb_fetching.py", line 22, in ?
> x_co = float(x_value[x])-float(x_value[x+1])
> IndexError: list index out of range
>
>
> can you suggest me the mistake i have made
>
suppose you have an x_value list of length 6. Valid indexes go from 0 to
5. Then x is going to start at 0 and go up to 5. The last time around
the loop the expression "x_value[x+1]" is going to try and use 6 as an
index, thus trying to address past the end of the list.

Since the data values are the RMS differences between successive points,
there are only five differences for a six-element list.

Try using

for x in range(len(x_value)-1):

instead.

By the way, you presented your question very well - all necessary
information was there, and you didn't put in any mistaken guesses about
what might be going wrong. Well done, and welcome to Python! You will
find you can learn it very quickly.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

--
http://mail.python.org/mailman/listinfo/python-list
Re: beginner in python [ In reply to ]
Hi
Welcome to python !
there a a few suggestions in ur code which is a good practice to follow.
In the snippet:

> > for x in range(len(x_value)):
> > x_co = float(x_value[x])-float(x_value[x+1])
> > y_co = float(y_value[x])-float(y_value[x+1])
> > z_co = float(z_value[x])-float(z_value[x+1])
> > data = math.sqrt(x_co)*(x_co)+(y_co)*(y_co)+(z_co)*(z_co)
> > print data

U suddenly change the indent from four spaces which u followed in previous
for loop. pls maintain consistency in indent. Standard convention is to use
four spaces for indent.

Another problem is that u have not closed the filehandle in the program!

HTH
KM
Re: beginner in python [ In reply to ]
Hi

pls redefine ur problem.
I donot understand what u wanted to accomplish .
is it that u wanted to check and represent the redundant entry numbers as
one entry or is it
with the isoform id as a single entry and without considering other data
like start and stop ?

also observe that when u consider the whole line in the data file, they are
all unique - there is no redundancy.

KM
-----------------------------------------------------------
On 8/2/07, Beema shafreen <beema.shafreen@gmail.com> wrote:
>
> Hi everybody ,
> I am a beginner in python,
> I have to fetch the redundant entries from a file,
>
> code:
>
> import re
> L = []
> fh = open('ARCHITECTURE_MAIN.txt', 'r')
> for line in fh.readlines():
> data =line.strip()
> # splitted = data.split('#')
> L.append(data)
> fh.close()
>
>
> M=L
> for x in L:
> x = x.split('#')
> for y in M:
> y = y.split('#')
> x_data = x[0],x[1],x[2],x[3]
> #print x_data
> y_data = y[0],y[1],y[2],y[3]
> #print y_dat
> if x_data[0] == y_data[0]:
> print x_data
>
>
> i get the result as a tupule,
> the text file which has datas separated by hash
> entry#isoform#start#stop# i have to check upto this
>
> 00250_1#ARCH_104#61#89#Literature#9224948#00250####
> 00250_1#ARCH_104#97#126#Literature#9224948#00250####
> 00250_1#ARCH_104#139#186#Literature#9224948#00250####
> 00251_1#ARCH_463#7#59#SMART##00251####
> 00251_1#ARCH_463#91#121#SMART##00251####
> 00251_1#ARCH_463#251#414#SMART##00251####
> 00251_1#ARCH_463#540#624#SMART##00251####
> 00252_1#ARCH_474#1#21#Literature#8136357#00252####
> 00252_1#ARCH_393#481#501#Literature#8136357#00252####
> 00252_1#ARCH_463#523#553#SMART##00252####
> 00253_1#ARCH_82#37#362#SMART##00253####
> 00253_1#ARCH_54#365#522#SMART##00253####
> 00253_1#ARCH_104#589#617#SMART##00253####
> 00253_1#ARCH_104#619#647#SMART##00253####
> 00253_1#ARCH_104#684#712#SMART##00253####
> 00254_1#ARCH_82#27#352#SMART##00254####
> 00254_1#ARCH_54#355#510#SMART##00254####
> 00254_1#ARCH_104#576#604#SMART##00254####
> 00254_1#ARCH_104#606#634#SMART##00254####
> 00254_1#ARCH_104#671#699#SMART##00254####
> 00255_1#ARCH_82#56#425#SMART##00255####
> 00255_1#ARCH_54#428#582#SMART##00255####
> 00255_1#ARCH_104#696#724#SMART##00255####
>
>
>
>
> can you suggest me ,what are the improvement i have to make in the above
> code
> regards
> shafreen
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Re: beginner in python [ In reply to ]
On 02/08/07, Beema shafreen <beema.shafreen@gmail.com> wrote:
> Hi everybody ,
> I am a beginner in python,
> I have to fetch the redundant entries from a file,
>
> code:
>
> import re
> L = []
> fh = open('ARCHITECTURE_MAIN.txt',
> 'r')
> for line in fh.readlines():
> data =line.strip()
> # splitted = data.split('#')
> L.append(data)
> fh.close()
>
>
>
> M=L
> for x in L:
> x = x.split('#')
> for y in M:
> y = y.split('#')
> x_data = x[0],x[1],x[2],x[3]
> #print x_data
> y_data = y[0],y[1],y[2],y[3]
> #print y_dat
> if x_data[0] == y_data[0]:
> print x_data
>
>
> i get the result as a tupule,
> the text file which has datas separated by hash
> entry#isoform#start#stop# i have to check upto this
>
> 00250_1#ARCH_104#61#89#Literature#9224948#00250####
> 00250_1#ARCH_104#97#126#Literature#9224948#00250####
> 00250_1#ARCH_104#139#186#Literature#9224948#00250####
> 00251_1#ARCH_463#7#59#SMART##00251####
> 00251_1#ARCH_463#91#121#SMART##00251####
> 00251_1#ARCH_463#251#414#SMART##00251####
> 00251_1#ARCH_463#540#624#SMART##00251####
> 00252_1#ARCH_474#1#21#Literature#8136357#00252####
> 00252_1#ARCH_393#481#501#Literature#8136357#00252####
> 00252_1#ARCH_463#523#553#SMART##00252####
> 00253_1#ARCH_82#37#362#SMART##00253####
> 00253_1#ARCH_54#365#522#SMART##00253####
> 00253_1#ARCH_104#589#617#SMART##00253####
> 00253_1#ARCH_104#619#647#SMART##00253####
> 00253_1#ARCH_104#684#712#SMART##00253####
> 00254_1#ARCH_82#27#352#SMART##00254####
> 00254_1#ARCH_54#355#510#SMART##00254####
> 00254_1#ARCH_104#576#604#SMART##00254####
> 00254_1#ARCH_104#606#634#SMART##00254####
> 00254_1#ARCH_104#671#699#SMART##00254####
> 00255_1#ARCH_82#56#425#SMART##00255####
> 00255_1#ARCH_54#428#582#SMART##00255####
> 00255_1#ARCH_104#696#724#SMART##00255####
>
>
>
>
> can you suggest me ,what are the improvement i have to make in the above
> code
> regards
> shafreen

Shafreen, your code snippet (as you posted it) prints any lines that
end with an entry code equal the entry code on the last line of the
file, with these lines split at #.

The whole thing (as you posted it) could probably be written something
like this:

===================
# not tested or optimised

fh = open('ARCHITECTURE_MAIN.txt').read().splitlines()
last_code = fh[-1].split('#')[0]
for line in fh:
if out_line.startswith(last_code):
print out_line.split('#')
# it will always print at least the last line of the file
===================

HTH :)
--
http://mail.python.org/mailman/listinfo/python-list
Re: beginner in python [ In reply to ]
It looks like you are doing some sort of molecular science thing.
Have you come across openbabel and the python bindings pybel
(http://openbabel.sourceforge.net/wiki/Python#Pybel). I don't know how
well they work but they might save you some effort. Also, check out
pymol,(http://pymol.sourceforge.net/) they might have some of the
functionality which you desire already coded!

HTH
Andy

Steve Holden wrote:
> Beema shafreen wrote:
>> hi everybody,
>> I am beginner in python
>> I have to calculate the euclidean distance between the atoms from a pdb
>> file
>> i have written the the code and its shows me some error ,
>> the code:
>> import re
>> import string
>> import math
>> ab =[]
>> x_value = []
>> y_value = []
>> z_value = []
>> fh = open("1K5N.pdb",'r')
>> for atom in fh.readlines():
>> a = atom.strip()
>> pattern= re.compile('^ATOM.*')
>> atom_file= pattern.search(a)
>> if atom_file:
>> atom_data = atom_file.group()
>> x_coordinate = atom_data[31:38]
>> y_coordinate = atom_data[39:46]
>> z_coordinate = atom_data[47:54]
>> x_value.append(x_coordinate)
>> y_value.append(y_coordinate)
>> z_value.append(z_coordinate)
>> for x in range(len(x_value)):
>> x_co = float(x_value[x])-float(x_value[x+1])
>> y_co = float(y_value[x])-float(y_value[x+1])
>> z_co = float(z_value[x])-float(z_value[x+1])
>> data = math.sqrt(x_co)*(x_co)+(y_co)*(y_co)+(z_co)*(z_co)
>> print data
>> ~
>> and the error ,message
>> File "pdb_fetching.py", line 22, in ?
>> x_co = float(x_value[x])-float(x_value[x+1])
>> IndexError: list index out of range
>>
>>
>> can you suggest me the mistake i have made
>>
> suppose you have an x_value list of length 6. Valid indexes go from 0 to
> 5. Then x is going to start at 0 and go up to 5. The last time around
> the loop the expression "x_value[x+1]" is going to try and use 6 as an
> index, thus trying to address past the end of the list.
>
> Since the data values are the RMS differences between successive points,
> there are only five differences for a six-element list.
>
> Try using
>
> for x in range(len(x_value)-1):
>
> instead.
>
> By the way, you presented your question very well - all necessary
> information was there, and you didn't put in any mistaken guesses about
> what might be going wrong. Well done, and welcome to Python! You will
> find you can learn it very quickly.
>
> regards
> Steve
--
http://mail.python.org/mailman/listinfo/python-list
Re: Beginner in python [ In reply to ]
On Tue, Oct 26, 2021 at 9:23 AM Kian Kwame <kiankayson@gmail.com> wrote:
>
> hi buddie
> am new to python somebody kindly advice the coding which will count odd number from 1 to 10 , and counting number from 1 tp 100

Sounds like homework. What have you written so far?

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
RE: Beginner in python [ In reply to ]
Chris,

I was just about to suggest:

1+3+5+7+9

and

50*101

but that would mean helping with what does seem like fairly simple homework
with no effort to show us what they already tried and got stuck with!

So, ignore my attempts at trivial humor as I suspect some form of loop was
anticipated.

Avi
-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
Behalf Of Chris Angelico
Sent: Monday, October 25, 2021 6:25 PM
To: Python <python-list@python.org>
Subject: Re: Beginner in python

On Tue, Oct 26, 2021 at 9:23 AM Kian Kwame <kiankayson@gmail.com> wrote:
>
> hi buddie
> am new to python somebody kindly advice the coding which will count odd
number from 1 to 10 , and counting number from 1 tp 100

Sounds like homework. What have you written so far?

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

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