880 Posted Topics
Re: [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: ")) … | |
Re: [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 … | |
Re: 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* … | |
Re: [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] | |
Re: Read this. [url]http://www.daniweb.com/forums/thread256661.html[/url] | |
Re: [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. | |
Re: [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] | |
Re: 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] | |
Re: 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] | |
Re: 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 … | |
Re: [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 … | |
Re: 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 … | |
Re: 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] | |
Re: 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 … | |
Re: 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. | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
Re: [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. | |
Re: Something like this. [CODE]def foo(num): ''' Return an exponential notation''' return '%e' % num print foo(3000000000000000000000000) #-->3.000000e+24[/CODE] | |
Re: 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] | |
Re: 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 … | |
Re: 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] | |
Re: Pyscripter version 2.0 is out now,support python 2.7. | |
Re: 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] | |
Re: 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> """ … | |
Re: 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 … | |
Re: 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 … | |
| |
Re: 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 … | |
Re: [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] … | |
Re: [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 … | |
Re: [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 … | |
Re: 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) … | |
![]() | Re: [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] |
Re: [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 … | |
Re: [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 … | |
Re: [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. | |
Re: 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 … | |
Re: 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 = … | |
Re: 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. | |
Re: [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 << '*' … | |
Re: [CODE]>>> l = ['12345'] >>> s = ''.join(l) >>> s '12345' >>> len(s) 5 >>> type(l) <type 'list'> >>> type(s) <type 'str'> >>> [/CODE] | |
Re: 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] | |
Re: Gui2exe work fine with python 2.6 It give a depreached warning,but that dont matter it works fine. | |
Re: 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 … | |
Re: [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 … | |
Re: 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] | |
Re: [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 … | |
Re: 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 … |
The End.