3,386 Posted Topics
Re: True never becomes False or similar False-like value so the loop continues until break statement or exception inside loop. ![]() | |
Another quick code over breakfast inspired by 'spying' the other forums. | |
Re: Without re, if surely good format: [CODE]>>> blah = """vcc = 2.6, clock = 1.5 Mhz vcc = 2.7, clock = 1.6 Mhz vcc = 2.8, clock = 1.7 Mhz vcc = 2.9, clock = 1.8 Mhz""" >>> blah = [line.split() for line in blah.splitlines()] >>> blah [['vcc', '=', '2.6,', … | |
Re: You should launch it in thread and kill it if result is not ready after 3 seconds. It more likely means that you have bad design for the function. What you want to do? | |
Re: You should use open instead of file at line for list_of_names: listofnames = file('twit.txt').readlines() listofnames = [name.strip() for name in listofnames] #--> list_of_names=[name.strip() for name in open('twit.txt')] But actually in code you only use it once, so making the list is kind of wasteful, generator would suffice: for name in … | |
Re: Do not also forget to test values where largest is less than -99. | |
Re: input takes every kind of Python expression and evaluates them. It should not be used and therefore it is removed from Python3. Format %.2f means: put here the variable after string and % with two fixed decimals format (like natural for currency). | |
Re: Or use switch statement not forgetting the breaks. | |
Re: Maybe you can find something from here: [url]http://www.lisp.org/alu/res-lisp-tools#guitool[/url] | |
Re: Think of what you have done before and what mistakes you did and why, how you succeeded and reasons for that. Do plan to avoid mistakes and do one better in successful strong points. The project work is other pro(cess/blem). After this you realize that you realy should really understand … | |
Re: Yes you can nest, but your request does not take one, only conditional expression in value part: [CODE] [x*x if x % 2==0 else x * 3 for x in range(1,20)][/CODE] | |
Re: GPL Octave is supposed to be mostly matlab compatible [url]http://en.wikibooks.org/wiki/MATLAB_Programming/Differences_between_Octave_and_MATLAB[/url] | |
Re: [url]http://en.wikipedia.org/wiki/Cycle_detection[/url] It includes code implementations in Python. It is not about graphs specifically, but functions. For graphs you can find for example: [url]http://en.wikipedia.org/wiki/Cycle_space[/url] | |
Re: Here is snippet of vegaseat in his sticky thread, how to use matplotlib and tkinter, maybe you can apply the example. | |
Re: How about [url]http://code.google.com/p/py-setproctitle/?[/url] | |
Re: I know this is C forum but I would like to bring up a point that programming is not language. Generally programmers can say: "I know this language best but I can learn any language others use, programming is programming." (most people have actually strong preferance, I for example generally … | |
Re: Another while loop around the line 20 would be clearer, although it is possible to just generate new value for x after response to continue and not to do the break. | |
Re: Sorry, but I do not love doing string processing in C. You could do manual PATH processing or find library to support that for you in C. Or you could find way to retrieve it from System Registry ([URL="http://lateblt.tripod.com/prgw32rg.htm"]with winreg.h[/URL]). | |
Re: That code of Schoil-R-LEA has bug in ranges (try str2int('98789', 10) for example) but if you take right interpretation as pseudocode, it will work for you. | |
Re: What you want to do with that strange line as strings have not method called accept? | |
Next quiz is posted as code snippet. It is quite interesting code. What it does? And where [B]in your system[/B] you already have this code? (in little different format) (If you have not follow tip in page [url]http://python.org/download/[/url]) | |
Re: So you are looping your [B]output[/B].txt with [B]i[/B]fp looks illogical naming. Why 'a' mode for ofp? (which is never used) Why lines 11 to 14 and at least why a<20 and b<20 and line 9 says char data[8][8][3]? | |
Re: You do not need database for simple phone dictionary, but if there is some usefull source of information, where information is always updated, it could be usefull to draw information there to avoid out of sync problems with not up to date info. Any language can handle it, spreadsheet is … | |
Re: For DOS there is for example the trusty old [URL="http://en.wikipedia.org/wiki/Turbo_Vision"]Turbo Vision.[/URL] | |
Re: How abot divmod or modulo % and integer division // ? You might find reading my base conversion snippet helpful. You can also make the str(n)[::-1] work by doing [CODE]' '.join(str(n)[::-1])[/CODE] | |
Re: Use functools.partial: [CODE]import functools def f(x): print(x) thislist = range(10) actions = [functools.partial(f, x) for x in thislist] for action in actions: action() [/CODE] | |
Re: I do not know, but I have coded the longest common substring algorithm and mayby you could use similar dynamic programming approach. [url]http://www.daniweb.com/software-development/python/threads/284870/1245223#post1245223[/url] | |
Re: Only line that could happen is line 2, if you have empty first line. You could change it to [CODE]ncols = len(rows[1])[/CODE] if second line is not empty | |
Re: Here you find tutorial for both Python2 and Python3: [url]http://python.org/doc/[/url] DaniWeb is great place to learn Python: [url]http://www.daniweb.com/software-development/python/threads/20774[/url] After these tutorials you should find out secrets of Python which your teacher has hidden from you :icon_rolleyes: | |
Re: This looks like worthy read: [url]http://jimmyg.org/blog/2009/working-with-python-subprocess.html[/url] | |
Re: Only this works: [CODE]class someclass: def __init__(self): self.somevariable='somevalue' def somefunction(self): print('gotta get here') def someotherfunction(instance): instance.somefunction() myclass=someclass() someotherfunction(myclass)#this needs to print 'gotta get here' [/CODE] as myclass.somevariable is only one string and has nothing connection with someclass. Or must save self in init: [CODE]class someclass: def __init__(self): self.somevariable= self, 'somevalue' … | |
Re: Also, do you see something strange in here? [CODE]/* Return Value: returns statement in parenthesis. */ void greeting ()[/CODE] | |
Re: I have simple algorithm for you ;) [LIST=1] [*]Learn to think [*]Learn basic math [*]Learn software design [*]Learn C++ [*]Learn to use IDE [*]Learn to debug [/LIST] Points 4, 5 and 6 need actually some parallel processing :) | |
Re: Your question seems upside down: "How I can use this solution, which does not work or does not work allways, to problem I have which I do not tell to you" | |
Re: For me this is only way (OS uses of course loop): [CODE]#include <stdio.h> #include <stdlib.h> int main() { int n; char range[298] = " 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99"; printf("Number between 1 and 99: "); scanf("%2d", &n); if(n > 99 && n < 1) { printf("Not … | |
Re: May you tell, why you need single quotes, which you can do many ways, including repr function? | |
Re: I think you run circles: if you want to know how much *int increase by pointer increment in a C implementation it is equivalent to finding [B]sizeof int[/B] which is easy to find and there must be one standard constant for that defined somewhere. | |
Re: You mean [url]http://en.wikipedia.org/wiki/Abstraction_layer[/url], don't you? Or something else? | |
Re: Grib has fine idea, but you should check that first value does not inadvertedly become neighbour of last value (maybe it is allready, I do not catch your rules so well) Here more incomplete parsing with itertools.groupby, leaving list one level: [CODE] import itertools def is_bracket(c): return c in '[]' … | |
Re: Are you always multiplying the matrix by itself? | |
Re: [CODE]variable = 'testF' def testF(): print('Hello World!') def reflect(what): globals()[what]() def main(): reflect(variable) main() [/CODE] I did not get any error message like you said however, only complaint of trying to use string as variable after fixing the missing :, usually we however do not use string to pass, but … | |
The code demonstrates running program limitted time by following going over endtime expressed in seconds since midnight, so might fail for playing just midnight (add check that endtime is less than 24*60*60 if you want to be sure). Exciting action :) of the program is that it shows remaining time … | |
Re: Show what you trying to do, we need more information about what error you are getting with what data and by what code you trying to accomplish and what you want to accomplish. | |
Re: There is some unique dangers in doing scripptig as well as benfits (of course if you do Python). But you really can not generalize as it not only depends on programming language and nature of program but also clarity of mind and expression of the writer. By the danger I … | |
I thought to post some not quite so trivial as it looks quiz for Python, to test if your brain has Python installed OK ;) Try to figure out what interpreter answers (#? lines), then check with your Python interpreter of choice: [CODE]>>> a = list(range(10)) >>> a[1:1] #? >>> … | |
Re: What is purpose of replacing the parent class with instance of child class at line 5? I do not understand how it would function. Your first error message looks incomplete. | |
Re: Maybe most of activist have 2.6 (for psyco etc) and 2.7, maybe 3.2 installed. Also you could use portable version of some of them. Notice that 2.7 is quite much faster than 2.6 without psyco (often both faster than Python3). Also PyPy JIT compiler (written with subset of Python) is … | |
There was little buggy version of Python base conversion around, so here quick hack for my own program, including test with random numbers to verify it. |
The End.