snippsat 661 Master Poster

You have to use T not t
self.timer = wx.Timer(self)

snippsat 661 Master Poster

The question, how can I (if possible) replace all "value" with numbers in a quicker way then above?

Yes you dont need to store data from file,just iterate over the file and do replace.
And use with open() ,then you dont need to close fileobject.
This create a new file,this is ofen the best way so you dont mess up orginal file.

with open('val.txt') as f:
    for line in f:
        with open('new.txt', 'a') as f_out:
            f_out.write(line.replace('value', '1111'))
snippsat 661 Master Poster

Enalicho has give some tip.
Here a couple more.
Always use r(raw_string) for regex expression.
If you want to count,just use len() because re.findall() is returning a list.
Here is a example run.

>>> import re
>>> user_input = 'aaaaBBBCC'
>>> re.findall(r'A-Z', user_input)
[]
>>> #Missing []
>>> re.findall(r'[A-Z]', user_input)
['B', 'B', 'B', 'C', 'C']
>>> #Count
>>> len(re.findall(r'[A-Z]', user_input))
5
>>>
Enalicho commented: Good call; I shouldn't have left out the r +1
snippsat 661 Master Poster

You dont need to convert code just write it in python.
I could of course convert it to look exactly like C++ over,but that had been stupid.
Because python dos most stuff a lot eaiser than C/C++.

print 'Enter numers,use q to stop'
l = []
while True:
    user_input = raw_input('Enter numers: ')
    if user_input == 'q':
        break
    else:
        l.append(user_input)

num_list = (float(i) for i in l)
#Ascending order
print sorted(num_list)
#Descending order
#print sorted(num_list, reverse=True)
snippsat 661 Master Poster

Python has some extraordinarily intuitive features I'm noticing, it's almost...English.

List comprehensions as Gribouillis use is a common way to write with python.

>>> l = ['a', 'b', 'c']
>>> a = [x for x in l if not 'a' in x]
>>> a
['b', 'c']
>>> l
['a', 'b', 'c']
>>>

If we break up List comprehensions it look like this.

>>> lst = []
>>> for x in l:
...     if not 'a' in x:
...         lst.append(x)
...         
>>> lst
['b', 'c']
>>> l
['a', 'b', 'c']
>>>
snippsat 661 Master Poster

python --version not python--version
And as Gribouillis pointet out you can write python in any path(cmd) and it will work.
If environment variables(path) are ok.

You should stick with 2.7 for now,you can have both installed.
Most of stuff(tutorials/books/forum) out there is for python 2.x
The diffrence 2 to 3.
http://diveintopython3.org/porting-code-to-python-3-with-2to3.html

snippsat 661 Master Poster

This may help you,but this may not be an easy task for you if new to this and python.
Files i get from code under is.

110702SRace01_B.rtf
110702SRace03_B.rtf
110702SRace04_B.rtf
110702SRace05_B.rtf
110702SRace06_B.rtf
110702SRace07_B.rtf
110702SRace08_B.rtf

Files will be in folder you run script from.

from BeautifulSoup import BeautifulSoup
import urllib2
from urllib import urlretrieve


url = urllib2.urlopen("http://www.tvn.com.au/tvnlive/v1/system/modules/org.tvn.website/jsptemplates/tvn_sectionals.jsp?TVNSESSION=BD8A1BBD2F555AECA581698BFD1BDC6E.tvnEngine2")
soup = BeautifulSoup(url)

site = 'http://www.tvn.com.au'
race = soup.findAll('p', limit=1)
race = race[0].findAll('a', href=True)
for item,link in enumerate(race):
    #print link['href'] #Test print
    urlretrieve(site+link['href'], '110702SRace0%s_B.rtf' % item)
snippsat 661 Master Poster

Look at this post here i explain a little,and give a link to why regex is not the right tool for xml/html.
http://www.daniweb.com/software-development/python/threads/375186

from BeautifulSoup import BeautifulStoneSoup

xml = '''\
<text>
<p><s id="s1"><ng><w pws="yes" id="w1" p="CD">25</w> <w l="woman" pws="yes" id="w4" p="NNP"
common="true" headn="yes">Woman</w></ng> <vg tense="past" voice="act" asp="simple" modal="no"><w l="create"
pws="yes" id="w10" p="VBD" headv="yes">created</w></vg> <pg><w pws="yes" id="w18" p="IN">for</w></pg> <ng><w
vstem="succeed" l="success" pws="yes" id="w22" p="NN" headn="yes">success</w> <w l="barbie" pws="yes" id="w30"
p="NN" headn="yes">barbie</w></ng> <ng><enamex type="location"><w l="reynold" pws="yes" id="w37" p="NNP"
locname="single">Reynolds</w></enamex> <w l="sep" pws="yes" id="w46" p="NN" headn="yes">sep</w></ng>
<ng><timex type="date"><w pws="yes" id="w50" p="CD">1986</w></timex></ng> <ng><enamex type="organization"><w l="pari"
pws="yes" id="w55" p="NNP" locname="single">Paris</w> <w orgname="single" l="google" pws="yes" id="w61" p="NNP">Google</w>
<w l="limited" pws="yes" id="w68" p="NNP" common="true">Limited</w></enamex></ng></s></p>
</text>'''

soup = BeautifulStoneSoup(xml)
tag = soup.findAll('w', {'locname':'single' })
print tag[0].text #Reynolds

For fun one with regex.

import re

r = [match.group(1) for match in re.finditer(r'single">(\w+)', xml)]
print r[0]#Reynolds
Gribouillis commented: beautifulsoup pro +13
snippsat 661 Master Poster

One from me to,but remember that regex and html/xml tag is diffcult.
And parsing a website with many 100 <td> tags it will break down.
Thats why we have parser and do not you use regex for this.
But for practice this can be fun.

>>> import re
>>> s = '<tr align="right"><td>3</td><td>Matthew</td><td>Brittany</td>'
>>> r = [match.group(1) for match in re.finditer(r"td>(\w+)", s)]
>>> r
['3', 'Matthew', 'Brittany']
>>> r[1]
'Matthew'
>>>
snippsat 661 Master Poster

The problem here is not regex,because regex is the wrong tool when it comes to html/xml.
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
So two good parser for python is lxml and BeautifulSoup.

from BeautifulSoup import BeautifulSoup

html = '''\
<tr align="right"><td>3</td><td>Matthew</td><td>Brittany</td>'''

soup = BeautifulSoup(html)
tag = soup.findAll('td')
print tag[2].string #Brittany
snippsat 661 Master Poster

For 2.6 you can do it like this.

>>> l = ['162.10.2.1', '162.10.2.1', '162.10.2.1', '192.34.1.10', '172.11.2.9']
>>> d = {}
>>> for v in l: d[v] = d.get(v, 0) + 1
... 
>>> d
{'162.10.2.1': 3, '172.11.2.9': 1, '192.34.1.10': 1}
>>> for k,v in sorted(d.iteritems()):
...     print '%s - %s' % (k,v)
...     
162.10.2.1 - 3
172.11.2.9 - 1
192.34.1.10 - 1
>>>
snippsat 661 Master Poster

As tony postet you have to use a paser.
lxml is good,for me BeautifulSoup has alway been a favorit.

lxml is more upp date and has more features.
But BeautifulSoup is just one small file(easy to disbrute),and still dos a very good jobb.

The advantages with lxml and BeautifulSoup is that you can parse xml/html that is not correct written.
All xml module in standar library,will shut down on malformed xml/html.
Here just a demo with BeautifulSoup.

from BeautifulSoup import BeautifulStoneSoup

xml = '''\
<?xml version="1.0" ?>
<Books>
<Item>
<BookID>A001</BookID>
<Title>A Tale of Two Cities</Title>
<Author>Charles Dickens</Author>
<Language>English</Language>
<Year>1859</Year>
<Quantity>5</Quantity>
</Item>
<Item>
<BookID>A002</BookID>
<Title>The Lord of the Rings</Title>'''


soup = BeautifulStoneSoup(xml)
tag = soup.findAll('title')
for title in tag:
    print title.string

'''Output-->
A Tale of Two Cities
The Lord of the Rings
'''
snippsat 661 Master Poster

well here is a thought

Well here is an other thought,read the date of the thread Feb 26th, 2006
So maybe 5 years later NetByte now it,or have given up python years ago:confused:

snippsat 661 Master Poster

Counter() is a dictionary,then you can iterate over it with a for loop.

>>> l = ['162.10.2.1', '162.10.2.1', '162.10.2.1', '192.34.1.10', '172.11.2.9']
>>> l
['162.10.2.1', '162.10.2.1', '162.10.2.1', '192.34.1.10', '172.11.2.9']
>>> from collections import Counter
>>> d = Counter(l)
>>> d
Counter({'162.10.2.1': 3, '172.11.2.9': 1, '192.34.1.10': 1})
>>> for k,v in sorted(d.iteritems()):
...     print '%s - %s' % (k,v)
...     
162.10.2.1 - 3
172.11.2.9 - 1
192.34.1.10 - 1
>>>
snippsat 661 Master Poster

Use code tag next time you post.

import wx
class duff(wx.Frame):

    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,wx.ID_ANY,'Duffan Formula', size=(400,300)) #wx.ID_ANY
        self.panel = wx.Panel(self) #self.panel

        #self.panel on all
        g=wx.StaticText(self.panel,-1,"________________________________________________________",pos=(10,65))
        z=wx.StaticText(self.panel,-1,"Welcome to Duffan Formula!!",pos=(10,10))
        r=wx.StaticText(self.panel,-1,"Here you can discover the score of any girl you are looking for.",pos=(10,30))
        q=wx.StaticText(self.panel,-1,"Use it, with Knowledge!",pos=(10,50))
        a=wx.StaticText(self.panel,-1,"What`s her name?",pos=(10,110))
        b=wx.StaticText(self.panel,-1,"What`s her beauty score?",pos=(10,150))
        c=wx.StaticText(self.panel,-1,"What`s her body score?",pos=(10,190))
        average=wx.StaticText(self.panel,-1,"Average: ", pos=(80,222.5)).SetForegroundColour('blue')

        self.one=wx.TextCtrl(self.panel,-1,'Enter name',pos=(110,108),size=(80,20))
        self.two=wx.SpinCtrl(self.panel,-1,'1',pos=(150,148),size=(60,20),min=0,max=100)
        self.three=wx.SpinCtrl(self.panel,-1,'1',pos=(130,188),size=(60,20),min=0,max=100)
        wx.StaticBox(self.panel,-1,'Personal Info', (5,90),size=(250,160))


        ae=wx.Button(self.panel,label="Done",pos=(10,220),size=(60,20))
        self.Bind(wx.EVT_BUTTON,self.clickbutton,ae)
        self.Centre()
        self.Show(True)

    def clickbutton(self,event):
        '''
        Now this method can use self.panel
        Without self method can not use panel
        '''
        s1=self.two.GetValue()
        s2=self.three.GetValue()
        media = s1
        if  0<=media<=100:
            wx.StaticText(self.panel,-1, str(media) ,pos=(135,222)) #str(media)

if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=duff(parent=None,id=-1)
    frame.Show()
    app.MainLoop()
Ene Uran commented: sharp eye +13
snippsat 661 Master Poster

One way.

>>> ip = "192.168.157.128"
>>> ip = ip.split('.')
>>> ' '.join((hex(int(i))[2:] for i in ip))
'c0 a8 9d 80'
>>>
debasishgang7 commented: It helped me alot... +3
snippsat 661 Master Poster

One way with regex.

import re

with open('blah.txt') as f:
    for line in f:
        line = line.strip()
        result = re.findall(r'\d\.\d', line)
        print [float(i) for i in result]

'''Output-->
[2.6, 1.5]
[2.7, 1.6]
[2.8, 1.7]
[2.9, 1.8]
'''
snippsat 661 Master Poster

Try this,and use a simple script first where you not importing a lot of modules.
So you are sure that py2exe work

If you search this forum there are many post about how to use py2exe and cxfreeze.
You can also look into gui2exe that work fine.
http://code.google.com/p/gui2exe/
.

from distutils.core import setup
import py2exe
import sys

if len(sys.argv) == 1:
    sys.argv.append("py2exe")

setup( options = {"py2exe": {"compressed": 1, "optimize": 2, "ascii": 1, "bundle_files": 3}},
       zipfile = None,

       ##data_files = ['apple.jpg', 'cheese.jpg'],

       #Can use windows or console,replace my_file.py with py file you want to make exe off.
       #If not run in same folder give path /mydir/my_file.py
       windows = [{"script": 'my_file.py'}])
snippsat 661 Master Poster

how do I obtain inifo such as the name or the path of the folder,

Maybe i dont understand you,if you give the path to the folder.
Then you can store it in a variable and just print it out.

import os

aFolder = 'C:/test/'
print 'Top folder is %s' % aFolder
for root, dirs, files in os.walk(aFolder):
    for sub in dirs:
        print sub #Will print all subfolder in C:\test\

You have os.getcwd()
Return a string representing of the current working directory.

If unclear as @tony postet give more info.

snippsat 661 Master Poster

oooooo, so if I wanted to define a namespace, would make a folder with the same name as the namespace with a text file inside called __dict__, containing:

We are now talking about inner working og namespaces.
Python add to namespace auto and dont write strange code that use namespaces in a wrong way.
Writing code like this should be avoided almost always.

globals()[what]() | function = globals()[functionname] | globals()['b'] = 6 #same as b = 6

The Zen of Python.
http://www.python.org/dev/peps/pep-0020/

snippsat 661 Master Poster

is 'globals()' a namespace? and does a namespace work like a dictionary in the sense that you can add a key to a dictionary just by:

Yes globals() are a namespace.
A namespace is it`s just like dictionary.

*** Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32. ***
>>> a = 5
>>> globals()
{'__builtins__': <module '__builtin__' (built-in)>,
 '__doc__': None,
 '__name__': '__main__',
 '__package__': None,
 'a': 5,
 'pyscripter': <module 'pyscripter' (built-in)>}
>>> globals()['a']
5
>>> globals()['b'] = 6 #same as b = 6
>>> b
6
>>> globals()
{'__builtins__': <module '__builtin__' (built-in)>,
 '__doc__': None,
 '__name__': '__main__',
 '__package__': None,
 'a': 5,
 'b': 6,
 'pyscripter': <module 'pyscripter' (built-in)>}
>>>

Python has 3 namespaces global namespace, local namespace, built-in namespace .
We can take a look at local namespace.

>>> def foo():
...     x = 'i am local'
...     return x
... 
>>> foo()
'i am local'
>>> globals()
{'__builtins__': <module '__builtin__' (built-in)>,
 '__doc__': None,
 '__name__': '__main__',
 '__package__': None,
 'foo': <function foo at 0x01EE5AF0>,
 'pyscripter': <module 'pyscripter' (built-in)>}

>>> x #if we try to access x
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
NameError: name 'x' is not defined

>>> #x are local to fuction foo
>>> locals()
{'__builtins__': <module '__builtin__' (built-in)>,
 '__doc__': None,
 '__name__': '__main__',
 '__package__': None,
 'foo': <function foo at 0x01EE5AF0>,
 'pyscripter': <module 'pyscripter' (built-in)>}

>>> def foo():
...     global x #make x global
...     x = 'i am no longer only local'
...     return x
... …
snippsat 661 Master Poster

There is no problem all python 2.x books/tutorials will works for python 2.7.
It dos not mattter if it`s python 2.4 - 2.5 - 2.6,code will run fine in python 2.7.
New features for python 2.7
http://docs.python.org/dev/whatsnew/2.7.html
Only python 3 break backwardcompatibility.
This post is a good start.
http://www.daniweb.com/software-development/python/threads/20774

snippsat 661 Master Poster

Why do you need this?
Singel and dobbels quotes dos the same in python.

>>> s = "qwerty"
>>> s
'qwerty'
>>> print s
qwerty
>>> repr(s)
"'qwerty'"

>>> s = 'qwertys'
>>> s
'qwertys'
>>> repr(s)
"'qwertys'"
>>> print s
qwertys
>>>
snippsat 661 Master Poster

Yes of course didn't think of python 3.
xrange() in python 2.x,same as range() in python 3.
An python 3 has only range() that is returing an iteator.

snippsat 661 Master Poster

Just a note,maybe meant to give more brainwork to call a list on range()
that is returning a list.

>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
snippsat 661 Master Poster

Maybe a little confusing that line from richieking.
You should read link from tony because this i basic stuff you shold be able to figure out.

with open('your.txt') as f:
    for item in f:
        from_file = item.split(',')

for line in from_file:
    print line
snippsat 661 Master Poster

Just a note that can help.
New from python 2.7 is collections.Counter

>>> from collections import Counter
>>> l = ['j', 'a', 'n', 'k', 'o', 's', 'i', 'e', 'n', 'a', 'p', 'i', 'v', 'o']
>>> Counter(text)
Counter({'a': 2, 'i': 2, 'o': 2, 'n': 2, 'e': 1, 'k': 1, 'j': 1, 'p': 1, 's': 1, 'v': 1})

It also has a most_common feature.

>>> Counter(text).most_common(5)
[('a', 2), ('i', 2), ('o', 2), ('n', 2), ('e', 1)]
>>>
snippsat 661 Master Poster

Look at Qsettings if you want user to change and store settings in your UI.

snippsat 661 Master Poster

So a demo to the other way to install packages,easy_install is good to have and use.
I use easy_install most of the time.

I use same third party packages unidecode in this test.
http://pypi.python.org/pypi/Unidecode/0.04.1
I download Unidecode-0.04.1.tar.gz and pack it out,you pack it out to wherever you want.

Then from cmd i naviagte to the unpacked folder.
The wirte python setup.py install
Now unidecode is installed,test it out.

***Python 2.7 (r27:82525, Jul  4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32. 
>>> import unidecode
>>> dir(unidecode)
['Char',
 'NULLMAP',
 '__builtins__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 'unidecode']

>>> unidecode.unidecode(u"\u5317\u4EB0")
'Bei Jing '
>>>
snippsat 661 Master Poster

Tony has explain this,just a little more with code.

def something():
    a = raw_input('>> ')
    return a

print something()

As you something() has the return value.

def something():
    a = raw_input('>> ')
    return a

a = something() #store it in variable a
print a

One important fact with functions is that code local to that function,you have to call it.
That why a is not leaked out in global space.

No it work with making a global,but this is ugly and dont code like this.

def something():
    global a
    a = raw_input('>> ')
    return a

something()
print a
snippsat 661 Master Poster

You have to run kode in same folder as 'newfile.txt' or you have to give correct path.

f = open('c:/somefolder/newfile.txt','r+')

I do not have a
file there, but I thought you created a file with the same code?

Or as tony mention read(r) dos not create a new file only write(w) dos that.

snippsat 661 Master Poster

Convert to string and use len(),is the most commen way.

>>> n = 123
>>> len(str(n))
3
>>>

If your user input is returning a string like raw_input() in python 2.x and input() in python 3.x you can use len().
Then convert to integer if needed.
You can make function that takes integer as argument,and returning the lenght out.
A couple of example.

>>> u = raw_input('Enter a number')
Enter a number
>>> u = raw_input('Enter a number: ')
Enter a number: 123
>>> len(u)
3
>>> int(u) + 123
246

#A function
>>> def lenght(n):
	return len(str(n))

>>> lenght(12345)
5
>>>

Without converting to string.

import math
digits = int(math.log10(12345))+1
print digits #5
snippsat 661 Master Poster

WHat is QT?

QT(first link in google)

python and used pyside to compile it?

Pyside(GUI-toolkit) is a licence free versjon of QT.

You seems not so much uppdatet about this thing,so do a little searching.
Python is an easier language to learn and use than C++,python are used in many areas.
http://www.python.org/about/quotes/

snippsat 661 Master Poster

There is no problem creating a GUI like that in python.
The 3 big GUI-toolkit for python can all do that wxpython,PyQt,PyGTK.
A good news is also that QT,python has now Pyside(no licence problem for QT GUI framework in python)

snippsat 661 Master Poster

So then what is python used for if you can't create dekstop programs?

Of course you can create dekstop programs with python,in fact python is very good for that.
You have many good GUI toolkit like wxpython,PyQt,PyGTK.
And the god news for python pyside(no licence problem)
http://www.pyside.org/
You can also use java(swing) and .NET(winform) through python.

Some expample of program using this GUI-toolkit.
VLC(QT)
http://www.videolan.org/vlc/screenshots.html
Wxpython/wxwidgets
Dropbox- TrueCrypt - Digsby

In this link code for all GUI-toolkit.
http://www.daniweb.com/software-development/python/threads/191210

vegaseat commented: good info +15
snippsat 661 Master Poster

You have module like py2exe,cxfreeze,gui2exe that will give you(exe) to run without python installed.
If that what you mean.

snippsat 661 Master Poster

Tomboy python has BeautifulSoup and lxml that are pure(free) python tool and can parse any xml file even if it not validate.
As you see in my example over it works fine,no need to google for none python tools.

snippsat 661 Master Poster

The problem with with parser like xml.dom is that the xml most be perfekt.
Parser like BeautifulSoup an lxml can handle xml/html even if is not correct.
From BeautifulSoup wewbpage.

You didn't write that awful page.
You're just trying to get some data out of it. Right now, you don't really care what HTML is supposed to look like.

Neither does this parser.

snippsat 661 Master Poster
snippsat 661 Master Poster

Just to parse somthing for a start,i have not read to detailed about your task.
That xml you got is not the easiest xml i have seen.
I want to take out groupe and Thomson.

from BeautifulSoup import BeautifulStoneSoup
import re

xml = '''\
</VPpart>
<w cat="PONCT" ee="PONCT-W" ei="PONCTW" lemma="," subcat="W">,</w>
- <NP fct="SUJ">
<w cat="D" ee="D-def-ms" ei="Dms" lemma="le" mph="ms" subcat="def">le</w>
<w cat="N" ee="N-C-ms" ei="NCms" lemma="groupe" mph="ms" subcat="C">groupe</w>
<w cat="N" ee="N-P-ms" ei="NPms" lemma="Thomson" mph="ms" subcat="P">Thomson</w>
</NP>
- <VN>
<w cat="V" ee="V--P3s" ei="VP3s" lemma="avoir" mph="P3s" subcat="">a</w>
<w cat="V" ee="V--Kms" ei="VKms" lemma="informer" mph="Kms" subcat="">informé</w>
</VN>'''

soup = BeautifulStoneSoup(xml)
r = re.findall(r"C|P", str(soup))
tag = soup.findAll('w', subcat=r)

print [tag[i].string for i in range(len(tag))] #--> [u'groupe', u'Thomson']
snippsat 661 Master Poster

Two good parser are BeautifulSoup an lxml.
Can you post a part of xml file and tell what info you want out.
So maybe can i show a little about how to parse xml.

snippsat 661 Master Poster

A little basic stuff about Class/OOP stuff that can be good to now.
Remeber it`s not called a function but a method,when it belong to Class.

class Active(object):
    ''' Special method __init__() is called auto when you makeing a object(acts as Constructor)'''
    def __init__(self):
        self.players = []
        self.goblins = []

    def put_first(self, first):
        '''This look like a function,put when belong to a Class is called a method'''
        return self.goblins.insert(0, first)

    def __str__(self):
        '''Special method __str__  get used when we use print on a object'''
        return 'players: %s goblins: %s' % (self.players, self.goblins)

#Now let test out this Class in IDLE

Here we se two empty list because stuff under __init__ get called auto when we make an object

>>> a_object = Active() #Class instance,we are making a object
>>> print a_object #print find __str__,and print out object info
players: [] goblins: []
>>>

We put in a couple of goblins.

>>> a_object.goblins.append('Grunt')
>>> a_object.goblins.append('Killer')
>>> print a_object
players: [] goblins: ['Grunt', 'Killer']

Last we are using method put_first to place a goblin first in the list.

>>> a_object.put_first('Gotar')
>>> print a_object
players: [] goblins: ['Gotar', 'Grunt', 'Killer']
>>>
snippsat 661 Master Poster

Was anyone able to get easy_install pysnmp to work with python 2.7.1 and easy install 2.7 on windows? I get the following errors.

Yes as you see in my post over that it work,i use python 2.7
You get this Download error: [Errno 10065]
This mean that pypi can be down or problem with port/firwall on your pc.

You can download from pysnmp website and not use easy_install.
http://sourceforge.net/projects/pysnmp/files/pysnmp/2.0.9/
Then you use python setup.py install .

snippsat 661 Master Poster

look like it get and error on try to import numpy.
Try. help('numpy') .

Try this.

try:
    help('modules')
except Exception, e:
    print e

Or

try:
    help('modules')
except ImportError:
    pass

To get it to continue after ImportError.

Place for numpy C:\Python27\Lib\site-packages\numpy So you have to delete this folder is reinstall.
Remeber if you reinstall python,can 3 party modules like numpy not be removed.
You have to do it manually.

snippsat 661 Master Poster
snippsat 661 Master Poster

By the way snippsat is this program compatible with python 3.1 ?

Yes.

snippsat 661 Master Poster

You have just paste code into IDLE(python shell),that dos not work.
Do this file->new window now copy code under and paste code into the new window you got.

print ("Game Over")
input("Press the enter key to exit.")

Save the file with .py extension(somthing.py)
Now you can press F5 or Run Module from the menu.

IDLE(python shell) you can just type in 1 line and you have to hit enter after every line(if test more than line) and you se output immediately and also without print.

>>> print ("Game Over")
Game Over

>>> ("Game Over")
'Game Over'
>>> 
          
>>> for i in range(3):
...     i
...     
0
1
2
   
>>> a = 'hello'
>>> for word in a:
...     word
...     
'h'
'e'
'l'
'l'
'o'
>>>

Get a god editor make it eaiser to run code like pyscripter.
http://code.google.com/p/pyscripter/

Darion commented: Thankss :) +0
snippsat 661 Master Poster

The "is" statement should only be used when you want to check if
something is exactly and identical to None like "a is None" or "b is not None".
For everything else you should use == or !=.
There are some other use cases for "is", too.
But in general you shouldn't use "is".

snippsat 661 Master Poster

Google finance has a "Get quotes" function.
Here is a demo how we can use this function with python.
To get data here i use regular expression.
Regular expression and html can be hard,thats why parser often are better to use.
Will see if i write a BeautifulSoup to.

import re, urllib

def get_quote(symbol):
    base_url = 'http://finance.google.com/finance?q='
    content = urllib.urlopen(base_url + symbol).read()
    find_q = re.search(r'\<span\sid="ref_\d+.*">(.+)<', content)
    if find_q:
        quote = find_q.group(1)
    else:
        quote = 'no quote available for: %s' % symbol
    return quote

def main():
    #print get_quote('ibm') #168.28

    #Test of 5 companys
    Companys = ['google', 'ibm', 'microsoft', 'apple', 'nvidia']
    for i,value in enumerate(Companys):
        print '%s --> %s' %  (Companys[i],get_quote(value))

        '''Output-->
        google --> 525.10
        ibm --> 168.28
        microsoft --> 25.52
        apple --> 350.70
        nvidia --> 18.52
        '''

if __name__ == "__main__":
    main()
snippsat 661 Master Poster

As postet over using site API can help.

For webscraping are BeautifulSoup and lxml good parser.
Just a quick example with BeautifulSoup,take out price of bean.

#Python 2.x
from BeautifulSoup import BeautifulSoup
import urllib2

url = urllib2.urlopen('http://beans.itcarlow.ie/prices.html')
soup = BeautifulSoup(url)
#print soup #site conteds

tag = soup.find('strong')
print tag  #[<strong>$6.36</strong>]
print tag.string  #$6.36
Thisisnotanid commented: Provided helpful information. +2