3,386 Posted Topics
Re: I do not know other things than that property is one builtin class dealing with decorators. | |
Re: Here is my going around and finally I got there, but not maybe most elegant way as Python did not allow me to take ord from the individual bytes making utf8 letter. So I ended up manipulating the repr of that letter by string manipulation. [CODE]a=unichr(0x3001) b=a.encode('utf8') print b c=repr(b) … | |
Re: You have not clear how to call a function and define one. Here that point corrected version, You are also writing to file fs, which you opened for reading ('r'). [CODE]def filter(li, n): fs = open(li, "r") fd = open(n, "r") while 1: txt = fs.readline() if txt =="": break … | |
Re: Maybe better to use os.path.join, works also in not-Windows (or should I say Windows' complement :-) ) [CODE] import sys,os >>> sys.path.append(os.path.join('..','log')) >>> sys.path[-1] '..\\log' >>> [/CODE] | |
![]() | Re: I spotted that it has program, but I do not understand the re module enough to tell how to use it. Here is my test for others to check easier. [CODE] import re def FindName(name,list1): """ searches for a pattern in the list, returns the complete list entry. Is case … |
Re: The code is not equal first has 5 lines and the other code has 8. | |
Re: List manipulation is usually done by taking out first or last element in list. As Python lists are not really not list as much as arrays in other languages, just mixed, dynamic type, Python lists can efficiently be accesses through indexing t1=L[0] as you said. If you need to reference … | |
Re: Some problem with your function included down. Strange, the printed message comes only from calling the function from command line, not in loop going over range. [CODE]>>> numtoword('11') sorry that number is not in the list >>> ================================ RESTART ================================ >>> ---------- -1 nine 0 zero 1 one 2 two … | |
Re: [url]http://www.daniweb.com/forums/thread162126.html[/url] [ICODE]a=round(0.7893948, 3)[/ICODE] if you only want to print it so, you can do [ICODE]print "%.3f" % 0.7893948[/ICODE] You can use this also to prepare result as string [ICODE]s= "%.3f" % 0.7893948[/ICODE] This answers are with 0 not with . only. That you must check separately for example [CODE] >>> … | |
Re: Nice piece of work, especially [icode]all(c in '+-.0123456789' for c in num_str)[/icode] if you can trust the correctness of input. Has some problems though: [CODE] >>> Enter a number: 1.234.567 Traceback (most recent call last): File "D:/Tony/input_num.py", line 45, in <module> num = input_num() File "D:/Tony/input_num.py", line 12, in input_num … | |
Re: Regexp I do not know in python, but here one more time native python scanning with partition [CODE] MyStr = """ <tr> <td><a leave </a></td> </tr> <tr> <td><a remove </a></td> </tr> <tr> <td><a leave </a></td> </tr> <tr> <td><a remove </a></td> </tr> """ before ,found,t = MyStr.partition('<tr>') print before,found, ## leave … | |
Re: Use my piece of code in code snippet [url]http://www.daniweb.com/code/snippet277460.html[/url] | |
Re: For simple lookup I gave this solution to other thread, of course special modules are maybe more powerful, but take some time to learn. Any way here it again: [CODE]MyStr = "<test>some text here</test> <other> more text </other> <test> even more text</test>" tlist = [] _,found,t = MyStr.partition('<test>') while found: … | |
Re: You said your network is inaccessible from outside your work, if I understood. Is it not better to have cron job in you machine checking for new builds and starting to do the build in your machine say every day when there is on at 5 am in your computer … | |
Re: I would do while loop with partition: [CODE] MyStr = "<test>some text here</test> <other> more text </other> <test> even more text</test>" tlist = [] _,found,t = MyStr.partition('<test>') while found: t,found,more = t.partition('</test>') if found: tlist.append(t) ## no assignment, just append else: raise ValueError, "Missing end tag: " + t _,found,t … | |
Re: I would start with something like this. I would same time produce simulator for the code in the end. L == LOCCTR ?? [CODE]generate=False ## code generation on? ## adr parameter is the first column value, op is the third column (list?) def start(adr,op): global generate generate=True pass def byte(adr,op): … | |
Re: Interesting alternative to [CODE]>>> filter(lambda x:x>42,seq) != () ## any number in seq is over 42 True >>> filter(lambda x:x<11,seq) != () ## any number in seq is less than 11 False >>> filter(lambda x:x<12,seq) != () ## any number in seq is less than 12 True >>> filter(lambda x:x<12,seq) … | |
Re: Sorry amount of red, but your code has really many problems. I did take out the tabs also by untabify, width=4. My comments: Strange assignments to for loop variable containing the digits of number, which you are drawing. [CODE]n="2 12345" ## lets work out the example input first n=n.split(' ') … | |
Re: Why not: [CODE] shape=[ ' ', '++++', 'xxxx', 'xxxx', 'xxxx', '----', ' '] r=0.123 print "".join(shape).count('x')*r [/CODE] Plus maybe format and connectivity checking? | |
Re: I think that perl expression would not catch the Failed part, even I do not know perl. I have not studied yet the python re -module for regular expressions. I have however used basic string scanning in one function converting date strings. This can be adapted to your use also. … | |
Re: Your code gives this [CODE]Traceback (most recent call last): File "C:/Documents and Settings/Veijalaiset/Omat tiedostot/Lataukset/fly.py", line 2, in <module> from livewires import games, color ImportError: No module named livewires >>> [/CODE] Need this package? [url]http://www.livewires.org.uk/_media/python/livewires-2.1-r2.zip[/url] Generates still after install: [CODE] Traceback (most recent call last): File "C:\Documents and Settings\Veijalaiset\Omat tiedostot\Lataukset\fly.py", line … | |
Re: I do not recommend working disk file. Usually computers have enough memory to keep full copy in memory.If you need to not read all db in memory, You can use special char as first in line and by pass it in your operations. Also editing can be interpreted as adding … | |
![]() | Re: Doing 10/3 in 20000 decimals: [CODE] >>> base=10**20000 >>> units,decimals = divmod(10*base/3,base) ##10/3 long number >>> print str(units)+'.'+str(decimals) [/CODE] For square root you must use own function: [CODE]>>> import math >>> x=(2*base,base) >>> math.sqrt(x[0]) Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> math.sqrt(x[0]) OverflowError: long int too … |
Re: circle of one unit is x**2+y**2=1 in normal x,y coordinates. computer graphics however have generally graphics pixels which run like text lines from up to down for y. Actually it does not matter for here as -y*-y=y*y Therefore unit circle y = (x**2-1.0)**(1.0/2) , x is between -1 and 1. … | |
Re: Why bother: [CODE] import random deck=[(x,y) for x in '23456789JQKA' for y in ['hearts','diamond','club','spade']] random.shuffle(deck) for i in deck: print i [/CODE] | |
![]() | Re: Or [CODE]>>> L = [[x*x for x in item] for item in [ [4,5,6] , [2,4,5]] ] >>> L [[16, 25, 36], [4, 16, 25]] >>> [/CODE] |
Re: don't use menu. Your assignment talks allways visible menu screen. Think of looking thsi in TV from sofa. Show the menu described and register keys mentioned for functions not mouse operated menu. | |
Re: [QUOTE=Hummdis;1190066] I'm kind of stickler for syntax and 'pass', 'continue' and 'return' statements since emacs and other CLI editors make note of those for the auto indent features. In any case, given what's here, you should be well on your way. :)[/QUOTE] I am sorry but you lost me with … | |
Re: [CODE] >>> ["12/1/200"+str(x) for x in range(7,11)] ['12/1/2007', '12/1/2008', '12/1/2009', '12/1/20010'] >>> [/CODE] | |
Re: [QUOTE][CODE] for name in company: generateMainPage(company [/code] [/QUOTE] Something wrong with your code, this call has not all parameters and not closing parenthesis. Please post cleaner version of the code. | |
Re: Strip removes all those letter which are in the argument out from the string object. Because you are only stripping '//EKTV\\\\a[B]e[/B]lmpsx' the other letters are not stripped. (\ is double, but it does not matter to strip.) [CODE]import os path='VTK/Examples/Test' ## let's use properly the directory separator from os.path pathlist=path.split(os.path.altsep) … | |
Re: Can you post values of parameters before call and error message and your current solution, don't forget code tags. [CODE] def myfunc(a,b,c,d): print a print b print c print d a=('here','is' ,'some', 'strings') b= " ".join(a) print b ## one list to many parameters myfunc(*a) [/CODE] | |
Re: Your error does not make sense. It is interactive shell error, not program error. What are you doing, send all data (even the myro module we have not, maybe teachers own module?) And you have not main program in your program, so it does not execute anything. | |
Re: I have not better alternative that only this interactive loop. Remember to mark thread solved if you think it solved. [CODE]from math import * def riemannFunc(hgLoc, a, b, intervals, func): sums = 0.0 size = float(b - a) / intervals for i in range(0, intervals): x = ((i+ hgLoc) * … | |
Re: See how period is used and how it's use can become similar to other values in the formula. Tony | |
Re: Can you mark solved or tell what is still unclear/post results? | |
Re: [QUOTE=jcao219;1194537]In my opinion, that assignment is a terrible assignment. I would rather use magic methods to make such a set class, i.e. __iter__, __setitem__, __eq__, __add__, __getitem__[/QUOTE] Also I think using dict for such data type as set is like using lists to implement strings. I can be wrong though. | |
Re: Please attach files. | |
Re: [QUOTE=pythonnewbie10;1191381]I have this program that i have been working on which plays rock paper scissors game with the user. but i need to modify it to so it contains a "best of x" loop then for it to stop as soon as the user or the COM has won Everytime … | |
Re: If you want to sort list were numbers are strings you have two ways to make it work. You can right adjust the filling with blanks (see my post on high score table) or zeros or you can transform them to integers or numbers with desimals, either before putting to … | |
Re: First hit from google brought this code [CODE] # ftptest.py - An example application using Python's ftplib module. # Author: Matt Croydon <matt@ooiio.com>, referencing many sources, including: # Pydoc for ftplib: http://web.pydoc.org/2.2/ftplib.html # ftplib module docs: http://www.python.org/doc/current/lib/module-ftplib.html # Python Tutorial: http://www.python.org/doc/current/tut/tut.html # License: GNU GPL. The software is free, don't … | |
Re: The code fails to run because you did not attach the 1.gif file. After creating one very small file from windows minesweeper screen capture. it worked rearly few times, I do not know what happened. Normally it gives this error [QUOTE] Traceback (most recent call last): File "D:\Tony\Tests\minesweeper.py", line 144, … | |
Re: graphics module for teaching by Zelle, I guess. [url]http://mcsp.wartburg.edu/zelle/python/python3/ppics2e_code/graphics.py[/url] | |
Re: Seems like it is for remote machines connection not inside your own computer. So looks like it is ssh connection program offering secure connection to remote machines. [url]http://www.lag.net/paramiko/[/url] | |
Re: This code runs. You overwrote your root and you were missing mainloop in the end. [CODE]from Tkinter import * root = Tk() root.title("Checkers") top = Canvas(root,width="800", height="800") ## !!! Was overwriting the root window ## Creates the black and white square background size = 100 cols = 8 rows = … | |
Ordering objects is one thing that is changing as we will move to Python3 Python 2.6 gives interesting results [CODE]a=[1,'23',('a','b'),False,[[]],[],'bc',['ab','34'],45,'0',{},True] >>> sorted(a) [False, 1, True, 45, {}, [], [[]], ['ab', '34'], '0', '23', 'bc', ('a', 'b')] >>> print True==1 True >>> print False==0 True >>> print False=='' False [/CODE] Python3 … | |
Re: Checking python docs (urllib2 HOWTO) gave this tutorial link [url]http://www.voidspace.org.uk/python/articles/authentication.shtml[/url] I have not used myself so I can not give direct example. | |
Re: I do not know but maybe you could show each picture before you start to process it, I do not know if the slow down is acceptable. I could not test your functions as it gave me error [CODE]>>> Traceback (most recent call last): File "D:\Tony\Tests\watermark.py", line 42, in <module> … | |
Re: In windows that webbrowser command openned file I put in argument in my Notepad2, configured text editor. Thanks, I was suffering for same missing as I wanted to have program to generate answers in fast speed and then open them in text editor. That is better solution than letting the … | |
Re: User interface suggestion. I did one high score list. I did it without yet saving to file. That is however trivial as info is kept as fixed length strings, no need eval, repr or \t. So one [icode]"\n".join(scores)[/icode] to file is enough. I would suggest this style of interaction with … |
The End.