3,386 Posted Topics
Re: How about using [url]http://docs.python.org/library/msvcrt.html[/url] Keyboard reading and console printing functions. Or maybe it is possible to use curses or readline routines? Also if user has input things in keyboard they are in keyboard history and user can return to them by arrow keys and correct them. | |
Re: Don't forget code tags please (now the # sign in tool bar) [QUOTE=gabyallheart;1216941]I have this program, is working good but i got error when the rows are full because stop and not keep going...can some one help me please..:) [CODE]import random class Rack(object): def __init__(self, cols, rows): self.rows = rows … | |
Re: How about doing 1) statistics run with that normal inmemory set and then taking the found starting numbers in memory to sort with repeated read of file for each starting number. Or you could write each ip xx.yy.zz.aa to file ipsxx.txt, where xx,yy,zz,aa are two number hex representations of ip … | |
Re: the suggestion is otherwise ok, but I would not redefine built in type list. | |
Re: Here is how: [CODE] >>> import random,string >>> t=[] >>> for i in range(20): s='' for j in range(random.randint(3,10)): s=s+random.choice(string.ascii_lowercase) print s t.append(s) ktpwmhc oottmafdv mlalyaig redmmtv bmoflbd gsagulicx qzfvmdz lsviy bdffmd bdmk dtqjnwhla lufobzcqk lfnnf ppv tghkzqxtja bouvqq dbccxvuke vvmmvxl saelhkhgya knwjvdsv >>> s 'knwjvdsv' >>> t ['ktpwmhc', 'oottmafdv', … | |
Re: How about this: [CODE]>>> import sys >>> for i in r"\x03\xa2": sys.stdout.write(i[:1]) \x03\xa2 >>> [/CODE] | |
Re: Maybe you could adapt my strategy in [url]http://www.daniweb.com/forums/post1210294.html#post1210294[/url] ?? | |
I started to think how to create up and down style loop, and what I ended up was this. Wanted to do it little unconventional way though to demonstrate the property of range as list.[code]for n in range(8): for i in range(n)+range(n-2,-1,-1): print i, print """ Output: 0 0 1 … | |
Re: (code) button must be used to paste program in understandable and original form. So you are not allowed to use built in sort or what? You did not give explanation of your title nor what is your request. Also why you are redefining the `__init__` instead of using object defined? | |
Re: Maybe you could use the properties of set objects: [CODE] >>> a=set(['1','a','b',2]) >>> '1' in a True >>> 1 in a False >>> 'c' in a False >>> [/CODE] You can also check this my code snipet for ideas: [url]http://www.daniweb.com/code/snippet282009.html[/url] | |
Re: Edit: [/code] without / [QUOTE=dreadyteddy;1213706]I am TRYING to write a program that finds restriction sites in a DNA file and returns a picture and information box of the enzyme which cuts it. My problems are; a) I have no idea if my program works past opening the file directory. b) … | |
Re: > Ok. I added a menu now. Everything working however, I want for it to ask me Want to continue adding (y) or (n). If no go to main menu. What do you think ? import time ## why this? menu = """ Choose the operation to do (1-2): 1) … | |
Re: You forgot code tags! [QUOTE=asthaynian;1214064]I'm trying to make quiz GUI. The GUI has one button and an entry box. The user presses the button and it asks a random question from using the world database. After 10 questions, it tells you the number correct and incorrect. I'm having a lot … | |
Re: Not ideal for that but for example there is pypy (see [url]http://pypy.org[/url]) python just-in-time compiler (not many modules included), which is quite heavy class of programming. If you want exe to speed up your program check that (I found however that file operations are quite slow in Windows with that) … | |
Re: Or maybe more Pythonicaly and not so difficultly (look it up, and see which one you prefer) [CODE] # multiple searches of a string for a substring # using s.find(sub[ ,start[, end]]) def multis(search,text,start=0): while start>-1: f=text.find(search,start) start=f if start>-1: yield f start+=1 print("tonyjv: pythonic generator") print(" from vegaseat's code") … | |
Re: It means it is file object ready to use. | |
Here is some saved interaction in command prompt. [CODE]>>> type((1,2)) <type 'tuple'> >>> (3*x for x in (4,4)) <generator object <genexpr> at 0x00E73EB8> >>> tuple(x**2 for x in range(10)) (0, 1, 4, 9, 16, 25, 36, 49, 64, 81) >>> set(x for x in range(10)) set([0, 1, 2, 3, 4, … | |
Re: Sorry, but because nobody has given yet answer let me offer the Pythonic version in my 'magic separator check' approach [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\:[0-9]{1,5} I do have some basics on regurlar expressions, though they come in some variations. I interpret that proxy is something in form 0+.0+.0+:9+ where 0+ is min 1, max … | |
Re: You need to click that code button before pasting the code, otherwise the white space is messed up! | |
This problem came up in one thread and here is my finalised version to follow changes of files in list of paths given. | |
Re: The point really is not to use len(a) but len(a)-1 as maximum. This also helps to understand why range(5) gives numbers 0 until 4. [CODE]>>> a=['a','b','c'] >>> print a[len(a)] Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> print a[len(a)] IndexError: list index out of range >>> for … | |
Re: Think progress of one game, what user sees, what he inputs, what computer shows/asks, how the game finishes. Find different objects and actions from the story and start coding. Post the results when you have created main logic and/or first part of the solution. By the way to get fixed … | |
Re: Does this help you? Pretty is my module which I posted you can replace it with normal prints and use your paths of course. [CODE]import os import pretty path_to_watch = [] path_to_watch.append("/Tony/Tests") path_to_watch.append("/Python Projects/") path_to_watch.append("/Python26/Lib/site-packages") before = [],[] for item, folder in enumerate(path_to_watch): ## print "i am here", item, " … | |
Re: Mayby your algorithm performance slows down like n**2 or n!. (O(n**2) or O(n!)) Or the memory is tight. Maybe you could put somewhere for .... in open(..) instead of string to compare? Could you post the hardest working function and maybe time the performance of with different. Also you could … | |
![]() | Re: I would call assigning None over given parameter to function very bad style, sorry to say so. I also do not like local variables never used after assignment like this parameter master. |
Re: If you disregard the tag info, including the qroups, which in example have different sets of user (you must split from <group to deal them separately): [CODE] oldfile = 'user.txt' filename = 'userchanged.txt' f1 = [line.strip() for line in open(oldfile, 'r') if line.startswith('<name>')] ## generator changed to list f2 = … | |
Re: That code is fundamentally wrong, I do not understand your post. It is impossible to run that code. For example you have defs without ':' [CODE] IDLE 2.6.4 >>> def askopenfilename(self) filename = tkFileDialog.askopenfilename(**self.options) print filename return filename SyntaxError: invalid syntax >>> Class App: SyntaxError: invalid syntax >>> [/CODE] You … | |
Re: If you could narrow down still more, include real error message, put as attachment any needed external files, could be possible to give ideas. As is only the top gurus can read this code without live run debugging. Could you put some prints just before error point or give super … | |
Re: I do not get any errors when running the code, could you include erron messages, input then, expected output and what you did to spot the problem (printing to spot the place of problem) | |
Re: You mean like this: [CODE] # # File: gui_secondGen_v0.02.pyw # Programmer: A. Smith # Created: 20100323 # Edited: 20100504 # Time: 10:01 # Notes: # 1) Working way down page. Class menu, screen, controls. # try: # Python2.x from Tkinter import * except ImportError: # Python3.x import tkinter as tk … | |
Re: Please use elif instead of if, except for the first condition, your function looks strange, those condiitions are mutually exclusive! better still prepare dict with the keys and do [icode]if event.Ascii in key_dict: buffer+=key_dict[event.Ascii][/icode] Maybe there is Keycode event for individual key detection in the module which you are using? | |
Re: I think from previous thread that only knowing existence of element is not enough in this case. here is some searching example in 2d: [CODE] yList = [['dog', 'cat']] myList.append( ['lizard', 'sheep', 'pig']) print myList for i,li in enumerate(myList): if 'sheep' in li: print 'sheep list is list %i:'%i,li print … | |
Re: [CODE] for property in self.lstProperty: if property.attrib["name"] == strProperty: #do something else: #do something else if did not break out of loop[/CODE] [CODE] >>> x=2 >>> for i in range(1,x): if x>3: break else: print 'Hello else' Hello else >>> x=4 >>> for i in range(1,x): if x>3: break else: … | |
Re: Does this help you? [url]http://www.youtube.com/watch?v=d39izaupvEg[/url] | |
Re: This code was part of one post earlier in DaniWeb, I did not have energy now to pin point the post so I include it here (it was about polish characters I think) This code seems to have difficulty in doing ls or (dir) in root directory in WindowsXP at … | |
Re: This works directly as you wrote, if the length of tupple is 1 and contains only 1 two-tupple with same 0-elment [CODE] >>> if [('WER', 100)] < [('WER', 700)] : print "values for 2 is greater" #statements follow values for 2 is greater >>> [/CODE] | |
Re: [QUOTE=bpinheiro0186;1207734]Hey folks, I am new on the forum and new to Python. I am making a news site and using python/django. My site will get all the news from the DB and fill up the template. As there is about 10 lines for the news and at some moment i … | |
Re: I have done full anagram program with weeks of performance testing about which I did one post to this forum. These both programs look overly complicated. I will publish one word version based on my algorithm shortly as code snipet together with speed comparision to these posted versions. | |
Re: One Laptop per Child project based mostly on Python uses library called Pango to support special 3rd world country languages (maybe I saw even Farsi mentioned). Maybe you could check it out. [url]http://wiki.laptop.org/go/Farsi[/url] [url]http://www.google.fi/url?sa=t&source=web&ct=res&cd=2&ved=0CA8QFjAB&url=http%3A%2F%2Fwiki.laptop.org%2Fgo%2FTestimonials&ei=HCbgS--FLqecOKW2sa4I&usg=AFQjCNE5KWrg4xBqrV34hqnqieiQDIX99Q&sig2=xCQwP_r9WeIcfGWb7at2aw[/url] | |
Re: Or do without re: [CODE]## tennumber filter without re test="""4616186224 3501292628 2698109000 4398248508 8462632398 5414846117 9167449701 5097458418 4F882945714 456729994744 4563249 """ def tennumbers(a): sep=[x for x in a if not x.isdigit()] if sep<>[] : return "" ## not numbers elif len(a) == 10: ## ten numbers and newline return a+'\n' … | |
Re: Check out this code which does 8 buttons and handles them in one function. Any help? [CODE] #!/usr/local/bin/Python import Tkinter def doButton(buttonName): global but print buttonName class SimpleCallback: def __init__(self, callback, *firstArgs): self.__callback = callback self.__firstArgs = firstArgs def __call__(self, *args): return self.__callback (*(self.__firstArgs + args)) if __name__=="__main__": root = … | |
Re: Maybe good to copy link one time instead of download in the manual download and save the link to file, and post the file? Maybe repeat x times (maybe close browser in between) to see if clients_test# changes? Do search through links ignoring obviously wrong for final pattern in the … | |
Re: This should tell you the reason [CODE]>>> x= 0 >>> for i in range(9): x += 0.1 print x-0.9 # print the damn thing. if x < 0.9: print 'Yes' else: print "No" -0.8 Yes -0.7 Yes -0.6 Yes -0.5 Yes -0.4 Yes -0.3 Yes -0.2 Yes -0.1 Yes -1.11022302463e-16 … | |
Re: I would do it like this with list comprehension Little funny sequence as it includes only one element from a in formula. [CODE] >>> b[:2] [2, 10] >>> c=[a[0]+b[0]] >>> c.extend([sum(b[:x]) for x in range(2,len(b)+1)]) >>> c [2, 12, 18, 21] >>>[/CODE] | |
Re: If you want function instead of changing the order of sequence itself use sorted function. If you want in opposite order you can give reversed=True parameter: [CODE]>>> a=[4,2,6,0,7,3,9,21,15,12,17,1,0] >>> print sorted(a) [0, 0, 1, 2, 3, 4, 6, 7, 9, 12, 15, 17, 21] >>> print a [4, 2, 6, … | |
Re: Here one suggestion [CODE]import random noun = ['school', 'yard', 'house', 'ball', 'shoes', 'shirt', 'fan', 'purse', 'bag', 'pants', 'toaster', 'lamp', 'floor', 'door', 'table', 'bread', 'dresser', 'cup', 'salt', 'pepper', 'plate', 'dog', 'cat', 'wood', 'stool', 'suitcase', 'plane', 'bus', 'car', 'bike', 'phone', 'pillow', 'wall', 'window', 'bed', 'blanket', 'hand', 'head', 'bra', 'eyes', 'sock', 'plastic', 'card … | |
Re: By my thinking you are Ok to rename the files and directories can be renamed when the directory walking goes in one higher level go depth first in directories. So you can rename the files and do recursive renaming in subdirectories. Then last you can rename directories themselves. | |
This function I did to improve calculator program by eliminating problems with Pythons problem of dividing integer with integer and giving integer division result. | |
I tried this super simple class example from net. (Yes I am a beginner in implementation of object oriented features in Python) UPDATE: Now from fresh start of IDLE it did not crash, but did not quit properly still. Hmm. TaskManager any (or dozen) python zombies hanging around?? No only … |
The End.