python on window

S

sandeep patil

i have install python on window xp os.
C:/program files/python

i have done print program it working but .py can't working
help me to how i will execute this file this file where i will save
it.
path execution how .
tell me about any envorment veriable in python to set before python
editor run,it path. etc
************************************************************

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import posix
ImportError: No module named posix
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
inverted_phonebook=invert(phonebook)
NameError: name 'invert' is not defined index={}
for key in table.key():
value=table[key]
if not index.has_key(value):
index[value]=[]
index[value].append(key)
return index
************************************************************************
 
G

Gabriel Genellina

i have install python on window xp os.
C:/program files/python

i have done print program it working but .py can't working
help me to how i will execute this file this file where i will save
it.
path execution how .
tell me about any envorment veriable in python to set before python
editor run,it path. etc

You don't need to set any environment variable to run Python. (Perhaps
PYTHONPATH, but *only* if you put modules into non standard places)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import posix
ImportError: No module named posix

That's ok: there is no module named "posix" on Windows, it is only
available on Unix systems.

I've rearranged a bit your example. Write the following into a file named
test.py - use whatever editor you like (even notepad):

---begin file test.py---
def invert(table):
index = {}
for key in table:
value = table[key]
if not index.has_key(value):
index[value] = []
index[value].append(key)
return index

phonebook = {'sandeep':9325, 'amit':9822, 'anand':9890, 'titu': 9325}
print "Phonebook", phonebook

inverted_phonebook = invert(phonebook)
print "Inverted phonebook", inverted_phonebook
---end file test.py---

Then open a console window, change to the same directory where you saved
test.py, and execute:

python test.py

You should get:

Phonebook {'titu': 9325, 'amit': 9822, 'anand': 9890, 'sandeep': 9325}
Inverted phonebook {9890: ['anand'], 9325: ['titu', 'sandeep'], 9822:
['amit']}

There are plenty of tutorials about Python. A good book -among others- is
"Dive into Python"; you can buy the book, read it online, or even download
it from http://www.diveintopython.org/
 
J

jwelby

i have install python on window xp os.
C:/program files/python

i have done print program it working but .py can't working
help me to how i will execute this file this file where i will save
it.
path execution how .
tell me about any envorment veriable in python to set before python
editor run,it path. etc
************************************************************

SyntaxError: EOL while scanning single-quoted string>>> print ' sandeep "bhagwan " patil ,msc. java j2ee developer'

sandeep "bhagwan " patil ,msc. java j2ee developer

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import posix
ImportError: No module named posix

Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
inverted_phonebook=invert(phonebook)
NameError: name 'invert' is not defined>>> def invert(table):

index={}
for key in table.key():
value=table[key]
if not index.has_key(value):
index[value]=[]
index[value].append(key)
return index
************************************************************************

Hi Sandeep.

As you are working with Python on Windows, I would suggest that you
install the Python for Windows extensions from here:

http://sourceforge.net/project/showfiles.php?group_id=78018

It includes a very good application called PythonWin. Once installed,
PythonWin will be available under Python in your Start menu.

If you run PythonWin, File/New gives you the option to create a new
Python script. To begin with, you can save into the Lib folder of your
Python installation (probably C:\Python25\Lib). I usually add my
initials at the front of the script name to differentiate my scripts
from the standard ones if I put stuff in Lib.

You should be able edit your PYTHONPATH variable in PythonWin - see
the Tools options (though, now I look, my installation actually has a
bug in this function), or alternatively, you can add a folder to your
PYTHONPATH environment variable in RegEdit (if you know what you're
doing).

I hope this helps.

J.
 
J

jwelby

That should have been:

"You should be able edit your PYTHONPATH variable (should you need
to)..."

Gabiel is right, it's not usually required.
 
S

sandeep patil

i have written this program but i have gott following error,
in anather proram "indentation error" sir how i will indent in my
editor

#test.py index=()
for key in table:
value=table[key]
if not index.has_key(value):
index[value]=[]
index[value].append(key)
return index


Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
inverted_phonebook = invert(phonebook)
File "<pyshell#9>", line 5, in invert
if not index.has_key(value):
AttributeError: 'tuple' object has no attribute 'has_key'
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
interted_phonebook= invert(phonebook)
File "<pyshell#9>", line 5, in invert
if not index.has_key(value):
AttributeError: 'tuple' object has no attribute 'has_key'
 
M

Michael Bentley

i have written this program but i have gott following error,
in anather proram "indentation error" sir how i will indent in my
editor

#test.py index=()
for key in table:
value=table[key]
if not index.has_key(value):
index[value]=[]
index[value].append(key)
return index


Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
inverted_phonebook = invert(phonebook)
File "<pyshell#9>", line 5, in invert
if not index.has_key(value):
AttributeError: 'tuple' object has no attribute 'has_key'

If you define index as a dict instead of a tuple, you'll stop getting
that error -- but I'm afraid it still won't do what you want. Are
you trying to get a phonebook in which the values of the original
phonebook are the keys of the new one -- and the values are lists
(both 'sandeep' and 'titu' have the same number)? If so, try this:

def invert(table):
index=dict()
for k,v in table.items():
if index.has_key(v):
index[v].append(k)
else:
index[v] = [k]
return index

You had mentioned something about indentation error... If you'll
look at your definition of invert(), you can see that 'return index'
is inside the for loop -- which would cause a return before the
second time through the for loop. By dedenting (is that a word?) so
'return' falls directly below 'for', the for loop would have been
able to run to completion before returning.

Hope this helps,
Michael
 

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

Forum statistics

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

Latest Threads

Top