3,386 Posted Topics
Re: I think the editing should not take on share but should be copied to share after editing is finished, then there is not temp file in share. Each user could have own subfolder as mentioned allready. | |
Re: fileOpen = open("myFile%2i.txt" % fileIndex, "r") | |
Re: I do not see connection of your code with problem. | |
Re: Correct way is to use HTML parser like http://www.crummy.com/software/BeautifulSoup/ | |
Re: name = input("What is your full name: ").title() if name in ("John Cleese", "Michael Palin"): print("I do not like your name") elif name == "Jack Neilson": print("That's a very nice name") else: print("You have a nice name") | |
Re: I think it is usually quite opposite: it looks little strange to look some old newbie posts, when the poster has hundreds of posts and current signature by retroactive use of current info, and especially time they have now been members. Could it be easily changed to put the time … | |
What this produces and why? >>> a = 2 >>> b = 5 >>> exec "print(a+b)" in dict(a=6, b=9) | |
Re: Use [URL="http://docs.python.org/library/difflib.html"]difflib[/URL]. | |
Re: Considering the [almost ready answer given by your teacher](http://www.daniweb.com/software-development/python/threads/426980/cant-use-variable-outside-of-for-loop#post1827205) (even giving suggestions, against the common naming conventions of Python, but anyway, about names of variables) I for one do not feel like telling you ready answer. You were allready given advice about return value of function in the other thread. | |
![]() | Re: You have infinite recursion. What is wrong with Python itself? You could disallow the dangerous '_' character, though, for safety. Maybe only eval is OK. If you need control flow you must go with exec. ![]() |
Re: You can find tons of exmple code from http://www.daniweb.com/software-development/python/threads/191210/python-gui-programming And Python code snippets tab. | |
Re: Nice to hear about your triumpf! Maybe it was good lesson for you to formulate clearer question, and to make it possible for others to run your code, next time. If you want to be nice to others proper Daniquette is to post your solution, if it is free to … | |
![]() | Re: line 60 condition is always True as `or "some not empty string"` is never False value ![]() |
| |
Re: It was nice to have back even based on it, even I have not much chance of being appreciated of my[ prime code snippet](http://www.daniweb.com/software-development/python/code/425958/prime-starting-numbers) given the 4 year old newbie post it compares it to! | |
Re: For me it is little confusing as actual edit window has kind of *half preview* with the markup also showing. Also when the post is long and I am using mobile, even only to edit small typo, it is making it harder than necessary. Mostly it is OK, but not … | |
Re: Keep lower and higher bounds both in variables, which you update by user response for random, and call it only in one place in loop. | |
Re: Did you read this? http://www.linuxjournal.com/article/8497 | |
Re: You can only check return (a + b > c) && (a + c > b) && (b + c > a) | |
Re: And for any youngster not familiar of this GOTO statement (or am I only too optimistic?), here the classic document from archives of Computer Science history: https://files.ifi.uzh.ch/rerg/arvo/courses/kvse/uebungen/Dijkstra_Goto.pdf | |
Re: >line 26 needs to be if Fail == True: Or simply if Fail: | |
![]() | Re: OK, here for you start: from __future__ import print_function try: input, range = raw_input, xrange except NameError: pass def quit_(): raise SystemExit def plus(a, b): return int(a)+int(b) commands = {'echo':print, 'quit':quit_, '+':plus} while True: c = input('>>').split(None, 1) if len(c) == 2: c, args = c args = args.split() elif … |
Do not miss http://www.daniweb.com/community-center/geeks-lounge/threads/424660/code-snippet-contest | |
Re: On the Python front there could be worse things to do than to check about Sugar on sugarlabs.org. http://sugarlabs.org/ In addition to being Python based and open source (ever listened "read the source"? And Python source is really easy to read when done well) there is also the Smalltalkish [Etoys](http://activities.sugarlabs.org/fi/sugar/addon/4030) … | |
Re: Check [she-bang line](http://en.wikipedia.org/wiki/Shebang_%28Unix%29) in your script | |
What is prefered version on handling 'serialized' code snippets, with features added to previous post? I have posted a [polynomial expression snippet](http://www.daniweb.com/software-development/python/code/425151/class-based-polynomials-with-magic-methods#post1817526) to which I could not include the division part because original poster whose thread inspired me to start, have not proved finding his solution to the problem. Should … | |
Re: We first want to admire your code ;) | |
Re: As this is not performance critical code, this kind of place is one of those that I sometimes like to use the functional map invocation of function to all items: >>> ''.join(str(i)for i in range(10)) '0123456789' >>> ''.join(map(str, range(10))) '0123456789' >>> | |
Re: You do not read singly linked list backward, that is why it is called singly linked. You would basically need to build another singly linked list reversed while reading the list from front to back. The process would be same as not in place reversing the linked list function uses. | |
Re: I do not know how much this fuss is worth, looks like you are basically just after simple Python one-liner: >>> d = 'ABC <uvw <xyz some random data' >>> import string >>> print([w for w in d.split() if w.startswith('<') and len(w)==4 and all(c in string.ascii_lowercase for c in w[1:])]) … | |
Do you get content of oper right before trying it out? oper = ['plus', 'minus', 'times'] oper.extend('divide') How about do you know what happens when you run this? Big bang? ;) print('a' 'b' 'c') And this is same, isn't it`? c = 'c' print('a' 'b' c) | |
Re: > "C:\\Dir1\\Sub One\\Sub3\\Sub4\\Sub Five\\logfile.txt" Why are you using different names for logfile in the two different opens? Isn't it supposed to open file in same location? | |
Here you see how one could use recursion together with generators for (inefficient) permutations generator. It is kind of interesting to know how one can do it recursively (of course there exist many ways). Anyway this snippet demonstrates how you can use recursive generator call to feed a for statement. … | |
Re: Look into using list comprehesion or basic for loop with append. There is also map function that would fit your case but now the prefered way are the more versatile list comprehensions. | |
Re: I think there must be certain part of newbies that we can not change from one google wonders. I think we need certain number of atypical oldies who do not stop learning and maybe somebody else could take my path to learn by "when you do not know you teach" … | |
I googled little around for correct way to not reinventing of the wheel for expression evaluation (even I had done some simple evaluation check for my [Tkinter calculator snippet](http://www.daniweb.com/software-development/python/code/282548/simple-calculator) earlier). After getting totally upset with [this example](http://www.bestcode.com/html/evaluate_math_expressions_pyth.html), I made this with some struggles with `__builtins__` globals parameter of eval. First … | |
I am trying to write safyfied evaluator class, and get unexpected `__builtins__` added to dictionary after evaluation. Can somebody explain why/how it happens? import math def echo(n): print n return n def nothing(n): return n debug = nothing class MathParser(object): ''' Mathematical Expression Evaluator class. call evaluate() function that will … | |
Re: Do small array, say four elements and write to paper changed values after each line of code. | |
Re: More general snippet on the same subject can be found at [scan filetree for files containing text](http://www.daniweb.com/software-development/python/code/316585/scan-filetree-for-files-containing-text) | |
Re: a = q*b + r, where 0<=r<b, then a/b=q and r is the remainder, for example 5 = 2 * 2 + 1 so 5/2=2 and 5%2=1 | |
Re: Can you give example/timing data of your problem? Maybe you should read up on premature optimization? Int type is supposed to be most optimal in every platform. | |
Re: This snippet could probably be good foundation for file copy/installation with progress bar by adding function to call for each block. It could take parameters for current block number and total number of blocks. | |
Re: main is not void and you have not defined add and add1, a and b are uninitialized... you have not enough formats for your parameters in printf. | |
Re: I think you can not add characters to empty string passed to function in C. This would seem to work: #include<stdio.h> #include<string.h> void recurse(const char *, int); int main() { const char *charset="abcdefghij"; recurse(charset, strlen(charset)); } void recurse(const char *charset, int len) { int i; if(len>1) recurse(charset, len-1); for(i=0; i … | |
Re: %s, not %r: str not repr. height = raw_input("How tall are you? ") print "So, you're %s tall." % height | |
Re: This kind of situation is usually dealt with design pattern called delegation, but maybe better way is to isolate common functionality to separate class and inherit from it to both classes. | |
Re: Actually I could not find any object oriented code in your post, so no methods also. |
The End.