snippsat 661 Master Poster

By the way, you may want to look at the BeautifulSoup Python library for working with html files (and extracting text from them).

I agree with this,but now it look like boiishuvo will destroy the stucture of html.
Should it replace like this or keep <> intact?

>>> s = '<html>'
>>> s.replace('<html>', '***')
'***'

Something like this with regex.

import re

html = '''\
<html>
<head>
    <title></title>
</head>
<body>

</body>
</html>'''

print re.sub(r'<.*>', '****', html)
"""Output-->
****
****
    ****
****
****

****
****
"""
snippsat 661 Master Poster

You have to convert to int() or float().
If you concatenate two string then is just strings not numbers.

>>> '5' + '2'
'52'
a = raw_input("enter 2 numbers separated by a /: ") #5/2 entered
b = a.split("/")
c = int(b[0]) + int(b[1])
print c

You can also do it like this if you have a list with string.

>>> l = ['5', '2']
>>> [float(i) for i in l]
[5.0, 2.0]
>>> l = ['5', '2']
>>> map(int, l)
[5, 2]
>>> sum(float(i) for i in l)
7.0
snippsat 661 Master Poster

When you dont give path to "names.txt" as do in my example.
"names.txt" will be in same directory as you run the script from. open(r'C:\test\names.txt', 'w') here i give a path.
Read a little more in doc as Tony suggest.

snippsat 661 Master Poster

Look a a little messy,here a couple of way to write a list to a file.
If you need more help post a sample of list and how you want it to look in a file.

l = ['Fauntleroy Duck', 'Mickey Mouse']
with open('names.txt', 'w') as f_out:
    f_out.write(', '.join(l))

'''Output-->
Fauntleroy Duck, Mickey Mouse
'''
l = ['Fauntleroy Duck', 'Mickey Mouse']
with open('names.txt', 'w') as f_out:
    for line in l:
        f_out.write('%s\n' % line)

'''Output-->
Fauntleroy Duck
Mickey Mouse
'''
snippsat 661 Master Poster

sort() dos a in place sort of orginal list and it dont return anything.

>>> mystring = 'blue, pink, red, red, red, white, long, short, blonde, blonde'
>>> s = mystring.split(', ')
>>> s
['blue', 'pink', 'red', 'red', 'red', 'white', 'long', 'short', 'blonde', 'blonde']
>>> s.sort()
>>> s
['blonde', 'blonde', 'blue', 'long', 'pink', 'red', 'red', 'red', 'short', 'white']

>>> help(s.sort)
Help on built-in function sort:

sort(...)
    L.sort(key=None, reverse=False) -- stable sort *IN PLACE*

Use sorted() for store result in variable.

>>> s_sort = sorted(set(mystring.split(', ')))
>>> s_sort
['blonde', 'blue', 'long', 'pink', 'red', 'short', 'white']
snippsat 661 Master Poster

Dont use file as variable/argument is a built-in functions.

>>> f = open(file, 'a')
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
TypeError: coercing to Unicode: need string or buffer, type found
>>> file
<type 'file'>
>>>
snippsat 661 Master Poster

I am new to python and cant figure out what I am doing wrong with the global variables

Dont use global statement,because it is ugly.
Function should receive arguments and return value/s out.
Code should stay local to function,with global statement you are destoring that.
Use code tag,now i think it work as you expected.

#number = 0 why

def test():
    #global number ugly
    number = raw_input("Please type a number.") #return a string
    return number

def prints(number):
    #global number ugly
    #if number2 != 1: #Where is number2 coming from?
    if int(number) != 1: #make number an integer
        print "Yes"
    else:
        print "NO!"

number = test()
prints(number) #we give function test() return value as an argument to function prints()
snippsat 661 Master Poster
import re

def main():
    name = 'francis ford coppola'
    #space = name.find(" ") #will only find first space at 7
    space = [m.start() for m in re.finditer(' ', name)] #[7, 12]
    first = name[:space[0]]
    middle = name[space[0]+1:space[1]]
    last = name[space[1]+1:]
    print(first)
    print(middle)
    print(last)

main()

Without using regex module.

def find_index(name):
    name_index = []
    found = name.find(" ")
    while found > -1:
        name_index.append(found)
        found = name.find(" ", found + 1)
    return name_index

def main():
    name = input("Please enter a full name with 3 names, separated by one space: ")
    #name = 'francis ford coppola'
    space = find_index(name)
    first=name[:space[0]]
    middle=name[space[0]+1:space[1]]
    last=name[space[1]+1:]
    print(first)
    print(middle)
    print(last)

main()
snippsat 661 Master Poster

Hi use code tag next time,mark your code and press "code"
You only find first space at index 7.
The second one is at index 12

>>> name = 'francis ford coppola'
>>> space=name.find(" ")
>>> space
7

This:

name = 'francis ford coppola'
l = []
found = name.find(" ")
while found > -1:
    l.append(found)
    found = name.find(" ", found + 1)

print(l) #[7, 12]

Or simpler.

>>> import re
>>> name = 'francis ford coppola'
>>> [m.start() for m in re.finditer(' ', name)]
[7, 12]

Then you can use it like this.

>>> name = 'francis ford coppola'
>>> space = [m.start() for m in re.finditer(' ', name)]
>>> space
[7, 12]
>>> name[:space[0]]
'francis'
>>> name[space[0]+1:space[1]]
'ford'
>>> name[space[1]+1:]
'coppola'

There is a simpler way,i guess this is to learn about string slice.
Look at this.

>>> name = 'francis ford coppola'
>>> first, middle, last = name.split()
>>> first
'francis'
>>> middle
'ford'
>>> last
'coppola'
snippsat 661 Master Poster

I'm working on the py2exe convertor, which will convert files from .py to .exe

It seems like you are making this to diffcult and you are missing stuff like setup option.
Look at this,will convert py file to exe.

from distutils.core import setup
import py2exe
import sys

def py2_exe(file_in=None):
    if len(sys.argv) == 1:
        sys.argv.append('py2exe')

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

           ## Can use console or window
           ## Filpath to '....py' run this script in same folder as file_in
          console = [{'script': file_in}])

if __name__ == '__main__':
    #Use raw string then you dont need \\ or /
    file_in = r'c:\test\singel_digits.py'
    py2_exe(file_in)

There is also Gui2exe you can look at.

snippsat 661 Master Poster

The above code creates an array but, each element is 4 bytes each.

Not an array in python we call it a list.
A list in python is much more flexible than "array" as it`s called in C/C++,java.

Python has 3 types ints, longs or floats.
eight bits unsigned(can store 0-->255) so in python it`s a int.

I would like it to be as large as possible. I need it for a sieve prime number program.

In Python integers have a size only limited by your computer's memory.
If you want to force compatibility with C you can use Python module struct

snippsat 661 Master Poster

Just to simplify little and use better names.

import os

for root, dirs, files in os.walk(r'C:\test'):
    for f in files:
         if f.startswith('roads.'):
            print f
            #print os.path.join(root, f)

So this will print only files that starswith "roads" in directory c:\test.
we iterate over files and last line we can join root(path) with filename.

snippsat 661 Master Poster

Something like this should do it.

import re

text = '''\
BEGIN:VCARD
VERSION:2.1
REV:20110913T095232Z
UID:aac119d5fe3bc9dc-00e17913379d6cc8-3
N;X-EPOCCNTMODELLABEL1=First name:;Maj;;;
TEL;VOICE:09120000000
X-CLASS:private
END:VCARD
BEGIN:VCARD
VERSION:2.1
REV:20110228T083215Z
UID:aac119d5fe3bc9dc-00e17b0693898c98-4
N;X-EPOCCNTMODELLABEL1=First name:;Ali jahan;;;
TEL;VOICE:09120000001
X-CLASS:private
END:VCARD
BEGIN:VCARD
VERSION:2.1
REV:20110228T083510Z
UID:aac119d5fe3bc9dc-00e17b069df653a0-5
N;X-EPOCCNTMODELLABEL0=Last name;X-EPOCCNTMODELLABEL1=First name:Eqlimi;Mostafa;;;
TEL;CELL;1:+989120000002
TEL;VOICE:09180000003
X-CLASS:private
TEL;CELL;2:09390000004
X-CLASS:private
END:VCARD
'''

for match in re.finditer(r"CELL;\d:(.*)", text):
    print match.group(1)

'''Output-->
+989120000002
09390000004
'''
snippsat 661 Master Poster

I see that you have solved it,that`s god.
I did mix something together with regex when i saw the post.
Here it is not the cleanest soultion,but shoud work ok.

import re

text = '''\
BEGIN:VCARD
VERSION:2.1
REV:20110913T095232Z
UID:aac119d5fe3bc9dc-00e17913379d6cc8-3
N;X-EPOCCNTMODELLABEL1=First name:;Maj;;;
TEL;VOICE:09120000000
X-CLASS:private
END:VCARD
BEGIN:VCARD
VERSION:2.1
REV:20110228T083215Z
UID:aac119d5fe3bc9dc-00e17b0693898c98-4
N;X-EPOCCNTMODELLABEL1=First name:;Ali jahan;;;
TEL;VOICE:09120000001
X-CLASS:private
END:VCARD
BEGIN:VCARD
VERSION:2.1
REV:20110228T083510Z
UID:aac119d5fe3bc9dc-00e17b069df653a0-5
N;X-EPOCCNTMODELLABEL0=Last name;X-EPOCCNTMODELLABEL1=First name:Eqlimi;Mostafa;;;
TEL;CELL;1:+989120000002
TEL;VOICE:09180000003
X-CLASS:private
TEL;CELL;2:09390000004
X-CLASS:private
END:VCARD
'''

#Find names
name_re = []
for match in re.finditer(r"name:;.*|name:.*", text):
     name_re.append(match.group())
temp = re.sub(r'name|[:;]', ' ', ','.join(name_re))
temp = temp.strip().split(',')
names = [i.strip() for i in temp]

#Find voices
voice = []
for v in re.finditer(r"VOICE:(.*)|1:(.*)", text):
     voice.append(v.group(1)),voice.append(v.group(2))
voice = [i for i in voice if i != None][:3]


#Zip list together
result = dict(zip(names, voice))
print result
"""Output-->
{'Ali jahan': '09120000001', 'Eqlimi Mostafa': '+989120000002', 'Maj': '09120000000'}
"""
snippsat 661 Master Poster

You can look at this,and type is a reserved word in python.

class Object_refs(object):
    def __init__(self, descriptor_type, my_type, reference_count, flags=None):
        '''initializer method can be compared with constructor C++,but are not the same'''
        self.desctype = descriptor_type
        self.my_type = my_type
        self.refcount = reference_count
        self.flags = flags

Use class.

>>> descriptor_type = 1
>>> my_type = 'string'
>>> reference_count = 10
>>> obj = Object_refs(descriptor_type,my_type,reference_count)
>>> obj.my_type
'string'
>>> obj.my_type = '\u01'
>>> obj.my_type
'\\u01'
>>>
snippsat 661 Master Poster

Best way to create one is to not to.

Pseudo-random number generators are a very complex subject, so it's better off to use the implementations produced by the people that have a good understanding of the subject.

Python uses the Mersenne twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1.
The underlying implementation in C is both fast and threadsafe.

You can of course look at all code for python.
http://svn.python.org/projects/python/trunk/Modules/_randommodule.c
http://svn.python.org/projects/python/trunk/Lib/random.py

Pitfalls in Random Number Generation

def get_random_number():
    '''Chosen bye a fair dice roll,guaranteed to be random'''
    return 4
Gribouillis commented: nice post +13
snippsat 661 Master Poster

but I would at least be able to choose how many digits it goes out to, and not have it end prematurely. Do you have any suggestions?

There is no problem to control how many digits you want with decimal module use getcontext().prec or python string formatting.

>>> from decimal import *
>>> Decimal(1) / Decimal(7)
Decimal('0.142857')
>>> getcontext().prec = 2
>>> Decimal(1) / Decimal(7)
Decimal('0.14')
>>> print Decimal(1) / Decimal(7)
0.14
>>> getcontext().prec = 7
>>> Decimal(1) / Decimal(7)
Decimal('0.1428571')
>>> '%.2f' % (Decimal(1) / Decimal(7))
'0.14'
snippsat 661 Master Poster

Just to give you a hint with modulo operator as pyTony mention.

>>> 38 % 10
8
>>> 369 % 10
9
>>> 36 % 10
6
>>> 36999 % 10
9
>>>

So loop over element in list with modulo operator ,and use build in sum() to get result.

snippsat 661 Master Poster

If you think of something else than code under,give an example of list and task.

>>> l = [1,2,3,4]
>>> l[:2]
[1, 2]
>>> l[2:]
[3, 4]
>>> #Sum up last 2 digits
>>> sum(l[2:])
7
snippsat 661 Master Poster

Or "flag = False" after write in my code.
As you se pyTony use only with open ,wicht is an better option.

snippsat 661 Master Poster

Something like this, with open() close fileobject auto.
If you want line 2 also,change elif to if .

#test.txt
line 1
line 2
line 3 
line 4
f_out = open('outfile.txt', 'w')

flag = False
with open('test.txt') as f:
    for line in f:
        if 'line 2' in line:
            flag = True
        elif flag:
            f_out.write(line)

f_out.close()
'''Output-->
line 3
line 4
'''
snippsat 661 Master Poster

For python 2 and 3,i think you use pyhon 3 because you get error on print.

#Python 2.7
>>> print r"pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1", pow(2,3), pow(2,3,1)
pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1 8 0
#Python 3
>>> print(r"pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1", pow(2,3), pow(2,3,1))
pow(2,3) returns 2^3 pow(2,3,1) returns 2^3 modulo 1 8 0
>>> help(pow)
Help on built-in function pow in module builtins:

pow(...)
    pow(x, y[, z]) -> number
    
    With two arguments, equivalent to x**y.  With three arguments,
    equivalent to (x**y) % z, but may be more efficient (e.g. for longs).

>>>
snippsat 661 Master Poster

Windows look in environment variable(path) for python version.
http://www.windows7hacker.com/index.php/2010/05/how-to-addedit-environment-variables-in-windows-7/
To path you can add ;C:\python27\;C:\python27\scripts
Restart.
When you write pyhon in cmd python 2.7 will start.
Change to ;C:\python32\;C:\python32\scripts
Restart.
When you write pyhon in cmd python 3.2 will start.
This also mean that stuff get installed in python 3.2.
With the use of easy install or python module_name.py install

snippsat 661 Master Poster

An other way,nice use of itertools Gribouillis.

def blocks(filename, chunks):
    with open(filename) as f:
        numb_list = [i for i in f]
    return [numb_list[i:i+chunks] for i in range(0, len(numb_list), chunks)]

filename = 'numb.txt'
chunks = 4
print blocks(filename, chunks)

""" Out-->
[['56.71739\n', '56.67950\n', '56.65762\n', '56.63320\n'], ['56.61648\n', '56.60323\n', '56.63215\n', '56.74365\n'], ['56.98378\n', '57.34681\n', '57.78903\n', '58.27959\n']]"""
snippsat 661 Master Poster

One with regex you can look at,this is also not an ideal way when it comes to html.

import re

def find_attribute_value(html, att):
    s = re.search(r'%s="(.*?)"' % att, html)
    return s.group(1)

html = '''<img align=top src="photos/horton.JPG" alt="Image of StG instructor (Diane Horton)">', "src"'''
print find_attribute_value(html, 'src')
#photos/horton.JPG

print find_attribute_value(html, 'alt')
#Image of StG instructor (Diane Horton)
snippsat 661 Master Poster

Now do python have strong parser like lxml and BeautifulSoup,that do job like this much easier.

>>> from BeautifulSoup import BeautifulSoup
>>> html = '''<img align=top src="photos/horton.JPG" alt="Image of StG instructor (Diane Horton)">', "src"'''
>>> soup = BeautifulSoup(html)
>>> tag = soup.find('img')
>>> tag['src']
u'photos/horton.JPG'
snippsat 661 Master Poster

If .py files are assigned to be opened by python on your system, then you only need to put a shortcut into your startup folder.
C:\Documents and Settings\All Users\Start Menu\Programs\Startup

More andvance solutions is.
- add it to the windows registry (HKCU\Software\Microsoft\Windows\CurrentVersion\Run)
- package it into a service, that should then be installed

snippsat 661 Master Poster

I think you use python 3?
In python 3 input() return a string.
And formula will not work.
You can try this,and use code-tag also post error message(Traceback)

import cmath

print("Welcome to the Quadratic Program")
print("--------------------------------")

a = int(input("Enter a: "))
b = int(input("Enter b: "))
c = int(input("Enter c: "))

answer = (-b + cmath.sqrt(b ** 2 - 4 * a * c)) / 2
print(answer)
snippsat 661 Master Poster
import os

with open('file_1.txt') as file_1, open('file_2.txt') as file_2:
    f1 = [i.strip() for i in file_1]
    f2 = [i.strip() for i in file_2]
    comp =  [f for f in f2 if f not in f1]
    for f in comp:
        #print f
        #print os.path.basename(f)
        with open('new.txt', 'a') as f_out:
            f_out.write(f + '\n')

So in file_1 1.txt .
In file file_2 1.txt 2.txt 3.txt .
Saved to new.txt 2.txt 3.txt .

This will not work for you because your filename is strange. .ktb_ux453039 . amr.12.20.2002.tar~ In a normal case os.path.basename() would extract filename.

>>> import os
>>> os.path.basename('/root/desktop/python.py')
'python.py'
>>> os.path.basename('FILE /paci/ucb/ux453039/.ktb_ux453039 05/31/2006 17:52:04 09/01/2007 14:25:33')
'2007 14:25:33'

If your filename look like this i think write a regex is the only option,to extract those strange looking filename.

snippsat 661 Master Poster

And just an FYI: The Professor said the code could be done in very few lines (15 or less) so keep that in mind.

He was nice with 15 lines you can du a lot in python.

>>> ''.join(i + '*' for i in raw_input('word: '))
word: Hello
'H*e*l*l*o*'
>>> raw_input('word: ')[::-1]
word: Hello
'olleH'

You should try to break this up little,or Professor will understand that you got help.
Something like the code MS posted.

snippsat 661 Master Poster

When you use 's' it`s a string s,not variable s.

>>> int('s')
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 's'
>>> s = '42'
>>> type(s)
<type 'str'>
>>> x = int(s)
>>> x
42
>>> type(x)
<type 'int'>

@pyguy62 when you do s = 10,then s is a integer.
No need to convert to integer.

snippsat 661 Master Poster

When you get IOError,pass make it countinue to end.
Other errors than IOError will raise error as normal.

try:
  doSomething()
except IOError:
  pass
snippsat 661 Master Poster

You are making some mistake and it can be done much eaiser with some python power.
You are trying to count with dictionary 2 times 1 is enough.
.strip(',:.;')
You should take out more than this also ?!
An example.

>>> import string
>>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
>>> s = 'The quick:: brown! fox jumps? over+ the lazy?? dog.'
>>> ''.join(c for c in s if c not in string.punctuation)
'The quick brown fox jumps over the lazy dog'
>>>

So another way this time a complete script.

import re
from collections import Counter

with open('text.txt') as f:
    text = f.read().lower()
words = re.findall(r'\w+', text)

print(Counter(words).most_common(4))

This use regex \w+ that dos the same as i showed in code over remove special character.
And counting is done bye collections Counter new from 2.7-->
Counter also has a most_common function,that dos what name say.
This will show the 4 most common word in text.txt.

snippsat 661 Master Poster

You gone struggle with this if your regex and python skill are not so good.
This file is a mix of javascript and html.
Regex and html is not and the best fit,that`s why it exist parser like lxml and BeautifulSoup.

So this time you want to find something completely diffrent than the first post.
I use with open() then you dont need to close fileobject.

import re

pattern = re.compile(r'pr(.+i)n')
with open('test.txt') as f:
    for match in pattern.finditer(f.read()):
        print(match.group(1)) #eload" /><i

And why do you want to only find a part of word and some tag delimiter?

snippsat 661 Master Poster

Can you post a sample of the file.
You are making some basic mistake,so what you do will not work.

snippsat 661 Master Poster

You may have to give more exact info,like post more of the file.
Here is a regex example with the string you posted,that may need some changes to be more greedy.

import re

s = '(a,b){var c=encodeURIComponent,d=["//www.google.com/gen_204?atyp=i&zx=",(new Da "'
r = re.findall(r'\gen_(\d.*)="', s)
print(r) #['204?atyp=i&zx']
snippsat 661 Master Poster

But still nothing is working for webbrowser.get('whateverbrowser')

webbrowser.get('whateverbrowser') will search in environment variable path.
If it dont find path to firefox it will give back.
webbrowser.Error: could not locate runnable browser

So to environment variable path you have to add path to firefox.
;c:\...path to firefox for me it look like this ;C:\Programfiler\Mozilla Firefox\
Then restart and try again.

snippsat 661 Master Poster

i'm thinking maybe it's an indentation problem but I don't know

while if elif else while if elif continue if ..... a mess where am i now:confused:
Most can understand a while if elif else..,but if you nest it together then code lose readability.

The code will be much harder to debug/troubleshoot.
Write more function like you start of with,good code almost need no documentation.
I see you have get good help before in this post,i did start to look at your code but i lost motivation because of reason explaind.

snippsat 661 Master Poster

As Tony poster regex is not a god choice for html or xml.
This is why paser exist to do this job.

from BeautifulSoup import BeautifulSoup

html = '''\
<html>
...some code....
<B><FONT color="green">TEXT to BE EXTRACTED 1</FONT></B><br>
<P>
<B><FONT color="green">TEXT to BE EXTRACTED 2</FONT></B><br>
<P>
<B><FONT color="red">TEXT to BE EXTRACTED 3</FONT></B>
....some code....
</html>'''

soup = BeautifulSoup(html)
tag = soup.findAll('font')
for item in tag:
    print item.text

'''Output-->
TEXT to BE EXTRACTED 1
TEXT to BE EXTRACTED 2
TEXT to BE EXTRACTED 3
'''
snippsat 661 Master Poster

Post your code,not only Traceback.

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

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

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/