3,386 Posted Topics
Re: You should assign value of c first not last in if statement: [CODE]'Exercise 7.3' # modified program from exercise 7.2 print "press <Enter> to Exit!" while True: x_str = raw_input('Enter Start, [Stop], [Increment]: ') if not x_str: print "Exit Requested" break else: x_str_array = x_str.split(',') # splits the string where … | |
Re: [url]http://docs.python.org/py3k/tutorial/index.html[/url] | |
| |
Re: Can you explain what you mean by string of integers (bytes? memoryview?) Also you must explain what you have tried to do and how the result differed from your expectations to show proper effort. | |
Re: I will check, did not catch the logic first. not the way I would program it. Does not look idiomatic Python. Not at computer at the moment. Print statements are useful to see what happens: [CODE]def num_even_digits(n): numeven = 0 while n: temp = n / 10 if (n - … | |
Re: I have not used Abstract Base Classes until now, but this is about how I think I would organize your functionality (can not test without usage examples, seems to give syntax error in Python 2.7 but not in 3.2.2): [CODE]import abc import collections import math import weakref class AbstractNeuron(metaclass=abc.ABCMeta): def … | |
Re: [url]http://www.daniweb.com/software-development/python/code/280071[/url] is my snippet for email form. But you can easily adapt it to ip number check. | |
Re: What is if block after line 64, your code never will run. | |
Re: you are missing + to concatenate variable to the string. | |
Re: Check webbrowser module. | |
Re: Maybe this example helps. For this purpose I always use list comprehentions. Do not use n*[some_list] as it produces references to same list, not independent lists. [CODE]# pretty module from my code snippet in Daniweb: # http://www.daniweb.com/software-development/python/code/345935 import pretty def get_by_iter(data, iterable): # access data by single iterable instead of … | |
Got inspired to make computer to make moves in English Solitaire, I learned in childhood days to solve by myself consistently, no solving or game play interface at the moment (easy to add though). I added printing of the ready solution from the wikipedia, also maybe of your interest are … | |
Re: As I see, you are not getting any use out of your recursion, no modified self variables or using a return value from recursion (and actually no returned value in any case). And you should have one stack to keep saved states not new each time or I do not … | |
Re: edge detection? Or find first black pixels and see if it is corner, use it to choose between alternatives starting with 1 or starting with 0. I think you do not give full info, for example there must be some background also. | |
Re: [QUOTE=;][/QUOTE] Only the first link of original post is working: [url]http://www.daniweb.com/techtalkforums/faq.php?[/url] Start new thread with updated information and remove sticky from old post? | |
Re: Do function like: [CODE]>>> def change(ind, info): return '<p>%(ind)i: <a href="%(info)s" target="blank">%(info)s</a></p>' % locals() >>> change(1, 'www.google.com') '<p>1: <a href="www.google.com" target="blank">www.google.com</a></p>' [/CODE] | |
Re: [CODE]import sys, random, time, pygame, os, threading #where you are using threading etc from pygame.locals import * ### for example this ## do not produce list and run linear search from long range if mouse_down_x in range(420,470) and mouse_down_y in range(70, 120) and hunger[2] > 20 and hunger[3] == 1: … | |
Re: break command is used to exit the current for or while statement from middle of loop. | |
Re: Candidates in that Narue's suggestion could include languages Python, Ruby, Prolog, Lisp/Scheme, J, Forth, Icon, Haskel,[URL="http://www.muppetlabs.com/~breadbox/bf/"] Brainf.[/URL].. ;) | |
Re: This maze program seems to work without the listing of all locations. Nice hack to initialize many variables with chars this [ICODE]OPEN, WALL, START, END, SEEN, GOOD = tuple(' #SE!0')[/ICODE] Here is alternative algorithm finding the road through maze. Actually it is originally logic to move ball in Lines game, … | |
Re: You at least are missing ' before peanuts. And before , you have ) without starting ( | |
Re: I have only basic skills in C/C++, and do not know where you can get more help on that, but I am ready to help you make your final Python code nicer, of course the docstring stuff you should do yourself well as well as naming of the variables. Prepare … | |
Re: I happened to Google around for graphics and Prolog recently and got jealous of Mac people as [URL="http://xgp.sourceforge.net/"]XGP[/URL] seems to only support Cocoa interface. I myself learned Prolog with [URL="http://www.amazon.com/Art-Prolog-Second-Programming-Techniques/dp/0262193388"]Shapiro's book[/URL] and consider it quite a respectable job. | |
Re: basic framework for this kind of thing is normally something like [CODE]sep = '=' with open('myfile.txt') as filein: for line in filein: record = line.strip().split(sep) #process records fields[/CODE] | |
Re: Use split with second argument 1 or partition. [CODE]>>> "Sarah me hy uuuuu".split(" ", 1) ['Sarah', 'me hy uuuuu'] >>> "Sarah me hy uuuuu".split(None, 1) ['Sarah', 'me hy uuuuu'] >>> "Sarah me hy uuuuu".partition(' ') ('Sarah', ' ', 'me hy uuuuu') >>> [/CODE] | |
Re: Please use code tags not color tags. I do not know what the program is supposed to do (for example you are calling class method at line 41 in ping, there is not reconfigure method) you must pass the object to function (it could event be method in App, I … | |
Re: counter has not local parameter or variable named value. It is local because it is used at left side of assignement in function. You probably should have the variable as parameter of recusive function counter. You will hit the limit of recursion pretty soon so you better use regular loop. | |
Re: [CODE]for number in range(int(raw_input('How many? '))): open("%2i.txt" % number, 'w').close()[/CODE]or input if you use Python 3 produce more sensible 01txt etc number files. If you want different length names not in number order leave out the 2 length from format string. | |
Re: You do gui and put timer event to update word count. | |
Re: Your next job seems to be to learn about sequences like lists and tuples and replacing if..elif..elif... with dictionaries. | |
Re: If user enters negative numbers you discount them from total, is this correct? Use better names whuch are all self explanatory. | |
Re: Did you check the content of mechanize.py in documents directory? Looks strange directory name for installing a module. In IDLE there is even special menu option for opening module in file menu. | |
Re: difference is uninitialized from alternatives '1' and '2', do you mean it to be indented inside branch for '3'? | |
This code is based on code from series of programs [URL="http://www.ferg.org/thinking_in_tkinter/"]'Thinking in tkinter'[/URL] This code is not perfect, especially it does not recognize key release when mouse moves out of button area during push. Leave event could also be captured for that to stop the event in that case. | |
Re: Do not repeat code but use loop and argument with value from notelist by functools.partial. This code wont run as you have place holder functions without any statements, add pass statement. Record/Stop should be toggle switch changing the self.recording between True and False. Add self.recording check into play function. You … | |
![]() | Re: why you should use object hierarchy? Tell the reason for the code. The form looks fitting for recursive algorithm if you realy must do it this way. The names are not unique look for example doc directories or readme files. |
Re: Looks like it is trying to use modules from your system, not ones from the executable. | |
Re: You are not passing the line to your function and common idiom for inputting lines from file is: [CODE]with open('myfile.txt') as infile: for line in infile: #processing it[/CODE] time is not recommended name for variable name as it is standard library module name. | |
Re: Why would you use Button, instead of for example Canvas if this is what you need? | |
Re: The dictionary is undefined. Here in DaniWeb you must but [CODE] and same with / before CODE as tags not simple square brackets. Like this: ['scarcity', 'scarce', '[A],', 'ity', '[N|A]', '[N]'] scarcity scarce [A], ity [N|A] [N] scarcity [A], ['sweet', ','] sweet , Traceback (most recent call last): File "final3.py", … | |
Re: Still with this? :( [CODE]data = """prob=0.0093;ID=RGT430;BQRS=491;BRZ=-4.263;ID2=RT914;DRT=0.00;HRun=0;HaplotypeScore=0.2794; prob=0.003;ID=RGR301;BQRS=4;BRZ=-3.261;ID2=EV913;DRT=0.00;HRun=0;HaplotypeScore=0.2654; ....etcetc until last row: prob=0.345.""" def prob(line): if 'prob=' in line: line = line.split('prob=', 1)[1].rstrip('.') return float(line.split(';', 1)[0]) for line in data.splitlines(): pr = prob(line) if pr is not None: print(pr) [/CODE] | |
Re: [url]http://docs.python.org/copyright.html[/url] also you can type copyright at Python command prompt. | |
Re: Your code is just doing so stupid things like redefining 25 times in loop (and two unnecessary imports still), and you have got your basic code from Gribouillis, so we would really appreciate some honest efforts. | |
Re: Looks quite nice but line 2 (overwriten by for) and last three lines does not make sense to me. i have written code snippet for producing lowercased words from file, check it out from code snippet archive | |
Re: Your code looked too difficult for me to understand, so I cut it to bare essentials. I did however get buttons to appear in current turns rows with buttons and I put in pygame.quit() for clean finish with also Q and escape. However, I never coded in PyGame my own … | |
Re: Your indention is in unsupported format ;) CODE tags, please. This kind of condition for example is allways True: if hour >= 1 or hour <= 60: unlike for example this if 1 <= hour <= 60: | |
Re: No, Python way is known as "Ask for forgiveness, not permission". See for example my snippet: [url]http://www.daniweb.com/software-development/python/code/364647[/url] | |
Re: For me it would be lot cleaner style to use normal binary arithmetic for even/odd: [CODE]>>> def odd(n): return bool(n & 1) >>> def even(n): return not odd(n) >>> even(123123) False >>> odd(123123) True >>> [/CODE] If you want you could have class and have the things you like to … | |
Re: You should install either pygame-1.9.2a0.win32-py3.2.msi 6.4MB or instal Python 2.5.4 beside your Python 3.2 if you are able to learn both versions simultaneusly (like most regulars here do). |
The End.