880 Posted Topics

Member Avatar for KrazyKitsune

[CODE]from __future__ import division from math import sin from math import cos from math import tan from math import radians a = raw_input("enter 1 for sin, 2 for cos, 3 for tan") if a == '1': #most be string when compare(raw_input return string) degree1 = int(raw_input("Type in angle value: ")) …

Member Avatar for Stefano Mtangoo
0
620
Member Avatar for Tenck

[URL="http://www.swaroopch.com/notes/Python"]Byte of python[/URL] has also a python 3.x. The best advice is to stay with 2.7 for now,and later switch to python 3. Most pepole stay with python 2.x,because off many famous 3.party moduls has to be rewritten. There are many books tutorials that are really good for beginner and …

Member Avatar for snippsat
0
287
Member Avatar for guyfrompluto

NewbieXcellence import statement shall never be inside a function always on top. And the script dont work,where come tolist() from [B]your_array.tolist()[/B] Get this errormessage. This is when you give function a number and a list [B]one_way(5, [1,5,4])[/B] exceptions.AttributeError: 'list' object has no attribute 'tolist' [QUOTE]*can't find the delete post button* …

Member Avatar for Beat_Slayer
0
706
Member Avatar for Hawkeye Python

[CODE]>>> 1.0 - 2.718281828**(-(23.0**2)/730) 0.5155095380022271 >>> #Or import division from future >>> from __future__ import division >>> 1.0 - 2.718281828**(-(23**2)/730) 0.5155095380022271 >>> [/CODE] [url]http://www.ferg.org/projects/python_gotchas.html[/url]

Member Avatar for vegaseat
0
275
Member Avatar for Deeplop
Member Avatar for snippsat
0
193
Member Avatar for erogol

[QUOTE]What is the general usage area of python? Maybe I can change my question.[/QUOTE] Python are useful in many areas,read [URL="http://www.python.org/about/quotes/"]pytohn quotes[/URL] Whatever you want to do python has some excellent soltions in moste areas.

Member Avatar for snippsat
0
146
Member Avatar for pwnmercury

[QUOTE]is there fucntion like goto on C++ [/QUOTE] No,and i hope we never see goto it in python. [url]http://xkcd.com/292/[/url] Edsger W.Dijkstra wrote this in 1968. [URL="http://userweb.cs.utexas.edu/users/EWD/transcriptions/EWD02xx/EWD215.html"]A Case against the GO TO Statement[/URL]

Member Avatar for vegaseat
0
236
Member Avatar for rexona

There are possible to use sample,can write something compact like this. [CODE]>>> from random import sample >>> map(str,(sample(xrange(10),4))) ['1', '6', '2', '9'] >>> [/CODE]

Member Avatar for snippsat
0
186
Member Avatar for dj343

I havent tryed virtualenv,look like program much point to folder that you have to make. Something like this. [CODE]mkvirtualenv PROJECTNAME #Make a folder mkdir -p program add2virtualenv $(pwd)/program [/CODE]

Member Avatar for snippsat
0
116
Member Avatar for student_

Like this is it can be done without exception handling. Here it will loop until user enter a valid choice or quit. User can type in everthing and it will not break out in a error. Remeber [B]raw_input()[/B] return a string for everthing that user input. [CODE]print 'Enter a choice …

Member Avatar for snippsat
0
135
Member Avatar for KnifeDarky

[CODE]>>> tfile = open("text.txt", 'w') >>> help(tfile) | write(...) | write(str) -> None. Write string str to file. | | Note that due to buffering, flush() or close() may be needed before | the file on disk reflects the data written.[/CODE] As you see write takes string as an argument,so …

Member Avatar for snippsat
0
118
Member Avatar for Stefano Mtangoo

Link are not working but look the where working on a skinning system with xml. [url]http://wiki.wxpython.org/TG.Skinning[/url] Media player use a xml skinning system i think. Did find it here,but dont look like much have happend i last 4 years. [url]http://techgame.net/projects/Framework/wiki/SkinningFramework[/url] We could make this a post where we share idèe …

Member Avatar for Beat_Slayer
0
457
Member Avatar for rmsagar

if the ID always is a number without - If not change the regex. [CODE]import re text = '''\ xxxxx(xxxxx);xxx=xxxx,ID=1234-xxxxxxx (ID=4321),xxxxxxx/xxxxxxx-xxxxxxxxxxx (ID=3802))(xxxxxx=(xxxxxx=xxx)(xxxxx=xxxxxxx)(ID=3802))) ''' out_match = re.findall(r'ID=\d+', text) print out_match #-->['ID=1234', 'ID=4321', 'ID=3802', 'ID=3802'] [/CODE]

Member Avatar for rmsagar
0
99
Member Avatar for Archenemie

self has an important role in a class,it like a transporter off data in a class. You use [B]self.discountinput[/B] in [B]onAction([/B]) method. Then off course it will not find anything if you not using [B]self [/B]on what it`s looking for. Here is a fix so [B]wx.TextCtrl[/B] return data in to …

Member Avatar for Archenemie
0
101
Member Avatar for nezbo

Look into [URL="http://www.moviepartners.com/blog/utilities/ppb/"]Pygame Package Builder[/URL] In the link over there is link to gui2exe and cx_freeze you can try.

Member Avatar for snippsat
0
124
Member Avatar for PythonNewbie2

[CODE]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 …

Member Avatar for D33wakar
0
3K
Member Avatar for locomotive

Just some tips,you have to do something yourself. This regex [B][A-Z]\w[/B] will match Hi and My. --- Hi this is a test. My car is red. --- [CODE] import string >>> string.ascii_uppercase 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' #-------# >>> for num in range(65, 91): ... capLetter = chr(num) ... print capLetter ... A B …

Member Avatar for snippsat
0
139
Member Avatar for mst440

Now one will will code differential backups for you,and that is no point either Because you learn little from it. Start by moving and copying some files/folders around,like backup soultion most do. Look into [URL="http://docs.python.org/library/os.html"]os module[/URL] and [URL="http://docs.python.org/library/shutil.html"]shutil module[/URL] Some examples. [CODE]import shutil #Copy a file from test folder temp …

Member Avatar for snippsat
0
126
Member Avatar for stompper33

[QUOTE]Does Python offer any way of extracting just the data between my two dates?? [/QUOTE] Yes more than one way depends how data are organized. post an short example off that cvs file. Mark where 'initialDay' and 'finalDay' are.

Member Avatar for Beat_Slayer
0
3K
Member Avatar for Axelro

Something like this. [CODE]def foo(num): ''' Return an exponential notation''' return '%e' % num print foo(3000000000000000000000000) #-->3.000000e+24[/CODE]

Member Avatar for Axelro
0
279
Member Avatar for emchom

Your first code was a big mess. [CODE] def triangle(): totalRows = int(input("Please enter a number: ")) for totalRow in range(1, totalRows): print '*' * (totalRow) for totalRow in range(totalRows, 0, -1): print '*' * (totalRow) triangle()[/CODE]

Member Avatar for TrustyTony
0
244
Member Avatar for Joeflims

redyugi now you have 2 "int(raw_input" lines that do the same. To simplify it. The first function we dont give an argument,just retun value out. Remember run this code as a script and not in python shell(IDLE) [CODE]def get_celsius(): celsius = int(raw_input("Type in the Celsius temperature:" )) return celsius def …

Member Avatar for Joeflims
0
137
Member Avatar for cleve23

Use [URL="http://code.google.com/p/gui2exe/"]Gui2exe[/URL] I talk a little of what tool i use her. [url]http://www.daniweb.com/forums/thread303665.html[/url]

Member Avatar for snippsat
0
117
Member Avatar for Tommymac501
Member Avatar for plasticfood

indentations 4 space,is important in python. If you have a good python editor it will auto indent. [CODE]import wx class bucky(wx.Frame): def __init__(self,parent,id): wx.Frame.__init__(self,parent,id,'Frame aka window', size=(400,300)) panel=wx.Panel(self) status=self.CreateStatusBar() menubar=wx.MenuBar() first=wx.Menu() second=wx.Menu() first.Append(wx.NewId(),"new window") first.Append(wx.NewId(),"Open...") menubar.Append(first,"File") menubar.Append(second,"edit") self.SetMenuBar(menubar) if __name__=='__main__': app=wx.PySimpleApp() Frame=bucky(parent=None, id=-1) Frame.Show() app.MainLoop()[/CODE]

Member Avatar for plasticfood
0
153
Member Avatar for PythonNewbie2

Parser should skip the comments. I did a test in BeautifulSoup(3.08) dont use newer version. [CODE]xml = """ <Label> Hello!</Label> <!-- The above label says Hello. -- It is clear, no? Let's try spicing it up a bit. -- Add some color to it. --> <Label color="#FF0000">HI I'M RED-Y.</Label> """ …

Member Avatar for snippsat
0
2K
Member Avatar for Viasur

You have typing error. Special methods name always have to underscore [B]__init__[/B] [URL="http://docs.python.org/reference/datamodel.html#special-method-names"]special-method-names[/URL] Now it should work. [CODE]#!usr/bin/python # Filename: objvar.py class Robot: '''Represents a robot with a name.''' # A class variable, counting the number of robots population = 0 def __init__(self, name): #_init_ wrong __init__ correct '''Initializes the …

Member Avatar for Viasur
0
1K
Member Avatar for Aiban

Try this. [code=python] >>> import tkinter as tk >>> print(tk.filedialog.__doc__) File selection dialog classes. Classes: - FileDialog - LoadFileDialog - SaveFileDialog This module also presents tk common file dialogues, it provides interfaces to the native file dialogues available in Tk 4.2 and newer, and the directory dialogue available in Tk …

Member Avatar for jgomo3
0
12K
Member Avatar for -ordi-
Member Avatar for Stefano Mtangoo

It`s about same size,i guess you are talking about packed so it can run as an standalone application. PyQt is 3-4 mb larger for standalone application. I have got size down on wxpython quite a lot. Gui2exe(compressed: 2, optimize: 2 bundle_files: 3) Delete unnecessary files,so run [URL="http://upx.sourceforge.net/"]UPX[/URL] Last run [URL="http://www.jrsoftware.org/isinfo.php"]Inno …

Member Avatar for Stefano Mtangoo
0
293
Member Avatar for Fearx351

[CODE]>>> db = {} >>> h_back = 50 >>> db['hremspace'] = h_back >>> db {'hremspace': 50} >>> heremspace Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'heremspace' is not defined >>> #So you will get an NameError if hremspace only excit in a dictionary[/CODE] …

Member Avatar for Fearx351
0
143
Member Avatar for lewashby

[QUOTE]In the above code, why are the three lines following the second for loop encased in parentheses? And what is the last of those three lines.(639-randint? How did they just slap a number and a dash right in front of a function. Thanks for any and all replies.[/QUOTE] Why dont …

Member Avatar for TrustyTony
-1
310
Member Avatar for doomas10

[QUOTE]print list(word_pattern.findall(abstract))[/QUOTE] Just a tips. re.findall is returning a list,so there is not necessary to use list(). [CODE]import re text = '''\ hello, my name is george. How are you? Today i am not feeling very well. I consider myself to be sick. ''' word_pattern = re.findall(r'\w+', text) print word_pattern …

Member Avatar for doomas10
0
301
Member Avatar for rahul8590

For running code once you can write a function like this. [CODE]import time def test(): "Stupid test function" L = [] for i in range(100): L.append(i) def time_code(arg): '''For running code once,and take time''' start = time.clock() arg() end = time.clock() print 'Code time %.6f seconds' % (end - start) …

Member Avatar for Beat_Slayer
0
849
Member Avatar for jtaylor-bye

[url="http://www.daniweb.com/forums/thread20774.html"]This site[/url] [url="http://www.swaroopch.com/notes/Python"]Byte og python[/url] [url="http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python"]Non-Programmer's Tutorial for Python 2.6[/url] [url="http://www.tutorialspoint.com/python/index.htm"]Python tutorial[/url] Youtube. [url="http://www.youtube.com/watch?v=4Mf0h3HphEA&feature=channel"]Python basic[/url] [url="http://www.youtube.com/watch?v=RHvhfjVpSdE"]Wxpython[/url] [url="http://www.youtube.com/watch?v=0xgn-HKzZes"]Pygame[/url] [url="http://showmedo.com/"]Show me do[/url]

Member Avatar for lrh9
0
138
Member Avatar for Musing888

[QUOTE]from pyExcelerator import *[/QUOTE] Import shall always be on the top,[B]not[/B] inside a function. That`s why you get this warning. [B]SyntaxWarning: import * only allowed at module level[/B] DON'T do this: [B]from pyExcelerator import *[/B] unless you are absolutely sure that you will use each and every thing in that …

Member Avatar for Musing888
0
1K
Member Avatar for personx1212

[QUOTE]thanks for your help, i found a solution, installing C runtime library on the target machine can fix this problem, here is the link if any one needs it :[/QUOTE] Yes because it need "MSVCR90.dll". For Python2.6, this is MSVCR90.dll version 9.0.21022.8, which can be obtained from the Microsoft Visual …

Member Avatar for snippsat
0
155
Member Avatar for Archenemie

[CODE]'''-->my_file.txt x a b ''' text_label = [f.strip() for f in open('my_file.txt')][0] self.button = wx.Button(panel, label = '%s' % text_label) [/CODE] Take x from my_file.txt and place it as label text for button.

Member Avatar for Archenemie
0
115
Member Avatar for technocratic

Here is the code rewritten in wxpython,so you can compare. Wxpython is a good gui-toolkit and it look better in windows than Tkinter. [URL="http://www.esnips.com/doc/75edc5a7-c1bd-4770-8411-f580c2dd9f7a/vega_convert"]vega_convert_to_wxpython.rar[/URL] [CODE]import wx class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize) #---| Window color |---# self.SetBackgroundColour("light blue") #---| Panel for frame |---# panel …

Member Avatar for technocratic
0
2K
Member Avatar for student_

Like this,i have put function call in variable name and age. [CODE]def main(): name = makename() age = makeage() print "You are" ,age ,"years old", name def makename(): name = raw_input("Please enter your name ") return name def makeage(): year = input("What is the year current year? ") byear = …

Member Avatar for student_
0
83
Member Avatar for darknessamman

Try mechanize [url]http://wwwsearch.sourceforge.net/mechanize/[/url] [CODE]import mechanize browser = mechanize.Browser() browser.open("http://reg3.hu.edu.jo/huregister/") browser.select_form(nr=0) browser['user'] = "test" browser['pswd'] = "123" response = browser.submit() html = response.read() print html[/CODE] With this a get a 500 error,same same as login with wrong user/pass.

Member Avatar for darknessamman
0
135
Member Avatar for vulcano224

[CODE]for x in range(5): print x, #the same in C++ is: for (int x = 0; x < 5; x++) cout << x; [/CODE] [CODE]//C++ #include <iostream> using namespace std; int main() { int size; size = 4; for (int i = 0; i < size; i++) cout << '*' …

Member Avatar for vegaseat
-3
182
Member Avatar for Tommymac501

[CODE]>>> l = ['12345'] >>> s = ''.join(l) >>> s '12345' >>> len(s) 5 >>> type(l) <type 'list'> >>> type(s) <type 'str'> >>> [/CODE]

Member Avatar for woooee
0
4K
Member Avatar for Tightmopedman9

Look at wx.Timer set uppdate time in ms. [url]http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.Timer.html[/url] [url]http://wiki.wxpython.org/Timer[/url]

Member Avatar for Tightmopedman9
0
700
Member Avatar for manzati93

Gui2exe work fine with python 2.6 It give a depreached warning,but that dont matter it works fine.

Member Avatar for manzati93
0
146
Member Avatar for acrocephalus

Using global is not a good soultion at all,learn to give argument at return value out functions. A simple example. [CODE]def newUser(): Username = raw_input('Choose a username? ') return Username def reg_user(newUser): '''Make 3 users an save to a list''' l = [] for i in range(3): l.append(newUser()) return l …

Member Avatar for acrocephalus
0
10K
Member Avatar for acrocephalus

[CODE]>>> import texttable >>> dir(texttable) ['ArraySizeError', 'Texttable', '__all__', '__author__', '__builtins__', '__credits__', '__doc__', '__file__', '__license__', '__name__', '__package__', '__revision__', '__version__', 'len', 'string', 'sys', 'textwrap'] >>> table = Texttable() Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'Texttable' is not defined table = texttable.Texttable() #ok #We change …

Member Avatar for Gribouillis
0
2K
Member Avatar for tiddster

Something like this maybe. [CODE]import re html = '''\ "<meta http-equiv='content-type' content='text/html; cHarSet=gBk' />" ''' test_match = re.search(r'cHarSet\=(\w*)', html) print test_match.group() #-->cHarSet=gBk print test_match.group(1) #-->gBk[/CODE]

Member Avatar for snippsat
0
110
Member Avatar for aint

[CODE]import time def foo(): for i in range(100000): i def time_code(arg): start = time.clock() arg() end = time.clock() print 'Code time %.3f seconds' % (end - start) if __name__ == '__main__': time_code(foo) [/CODE] Most off the time code is to fast to measure only with one run,that`s why man use …

Member Avatar for snippsat
0
112
Member Avatar for kate2mba

Something like this,look into findall off re module. Dont use str as variable,it`s a builtin key word. [CODE]>>> str <type 'str'> >>> help(str) Help on class str in module __builtin__: [/CODE] [CODE]>>> import re >>> help(re.findall) Help on function findall in module re: findall(pattern, string, flags=0) Return a list of …

Member Avatar for kate2mba
0
151

The End.