2,646 Posted Topics
Re: In your script, add import sys raise RuntimeError(sys.path) This will show the directories used to find importable modules. If your directory is not here, you can try from distutils.sysconfig import get_python_lib raise RuntimeError(get_python_lib()) If this prints the `site_packages` directory where requests lives, you could try import sys from distutils.sysconfig import … | |
Re: Write pseudo code to show the logic of your code. I suggest while True: get user input if input is invalid: print error message continue process user input (update sum) if exit condition is met: break | |
Re: Some code is missing, I get Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'pnt' is not defined please post the code that generates your error message, plus full traceback. | |
Re: I know universities which use zimbra, and it works very well. | |
Re: You can also use `/usr/bin/pdfunite` to merge several pdf into one (in ubuntu, install package `poppler-utils` for this) | |
Re: It goes the other way round. If you're already running python 2, `sys.executable` is the path to the python 2.7 executable. If you're already running python 3, `sys.executable` is the path to the python 3.4 executable. If you want to run a script with python 3.4, use the command python3 … | |
Re: I don't see how tokenize can fail: it generates INDENT and DEDENT tokens that you could use to compute the indentation level. Also note that it is better to indent python code with space characters than tabs. A good python editor needs the 4 space indentation. Unfortunately, I'm not using windows tools … | |
Re: Try def extract_data(filename): with open(filename) as infile: v0 = next(infile) return v0, list(infile) Note that this will fail if there is no line in the file. | |
Re: You need to create a `Toplevel` window. There is a good example in the famous blog [Mouse vs Python](http://www.blog.pythonlibrary.org/2012/07/26/tkinter-how-to-show-hide-a-window/). Also study how Mike Driscoll uses of a `class App` in this example, in order to encapsulate tkinter code. The example was written for python 2, but it shouldn't be too … | |
Re: I only removed line 7 and it worked. Edit: You can also use this initialization NS = {'__builtins__': __builtins__} | |
Re: > insert between lines 70 and 71 this I updated the code accordingly. Note that a None value must be checked with the `is` operator. | |
Re: This may work while True: className=input("Are you enetring results for class a, class b or class c:>>>").strip().lower() if className in ('a', 'b', 'c'): break else: print('Invalid name, please enter a, b or c') | |
Re: Did you try `"%lf "` instead of `"%lf"` ? (see `man fscanf`) | |
Re: @David W This is also a universal problem with a known solution >>> lst = [ ['e', 1, 2], ['e', 2, 1], ['e', 1, 2], ['e', 2, 3] ] >>> lst2 = list(unique_everseen(lst, key=lambda x: tuple(sorted(x[1:3])))) >>> lst2 [['e', 1, 2], ['e', 2, 3]] unique_everseen is in the itertools module's … | |
Re: This is documented here [https://docs.python.org/3/c-api/long.html?highlight=pylong_fromlong](https://docs.python.org/3/c-api/long.html?highlight=pylong_fromlong). It may depend on the python implementation. | |
Re: There is a old thread [Click Here](https://www.daniweb.com/software-development/python/threads/325471/tkinter-updating-label-color) with an answer. Edit: you can also try hex colors such as `'#00ff00'` | |
Re: Perhaps the beginning of the end for google chrome ? | |
Re: Please post the code that you tried and why it fails. | |
Re: Here is how you could write occur(n) more simply big_set = [ ['78','18','79','56'], ['13','40','16','04'], ['63','70','78','60'], ['10','35','66','13'], ['32','41','71','70'], ['50','58','02','11'], ['13','40','41','05'], ['12','52','50','60'], ['71','13','66','12'], ['50','90','73','41'], ['09','18','44','54'], ['12','41','32','67'], ] def gen_sublist(n): for i, seq in enumerate(big_set[n+1:]): yield i, i+n+1, big_set[i], big_set[i+n+1] def occur(n): for i, j, a, b in gen_sublist(n): s = set(a) & … | |
Re: You could perhaps try df[...] = df[...].map(lambda x: datetime.strptime(x, '%H:%M:%S')) | |
Re: Did you run hp-setup ? [https://help.ubuntu.com/community/sane](https://help.ubuntu.com/community/sane) Edit: the hplip page [http://hplipopensource.com/hplip-web/models/other/envy_5640_series.html](http://hplipopensource.com/hplip-web/models/other/envy_5640_series.html) gives a list of distros for which the scanner works. If your distro is in the list, there must be a way to configure this properly. | |
Re: From my experience, it is usually easier to create pdf from another format, such as latex or rst or doconce or whatever. I never created a pdf file with *forms* because this seems to be very specific to adobe software. Apparently, there is a way to create pdf forms with … | |
Re: There is no backslash in your string, so I don't see the problem. there is only an ordinary slash, which has no special effect. Please describe what you expect. | |
Re: This seems to be working >>> url = urllib2.urlopen('http://www.python.org') >>> soup = BeautifulSoup(url) >>> srcs = [img['src'] for img in soup.find_all('img')] >>> srcs ['/static/img/python-logo.png'] >>> | |
Re: The arithmetic operations don't work for me. Only the sqrt works. | |
Re: It seems to me that you only need to remove lines 14 and 18 from the above program to get a start. | |
Re: Remove all the `aNa` variables from this program. Use `word[N]` etc. | |
Re: Did you read this help page https://help.ubuntu.com/community/Mount/USB ? | |
Re: Note that in python 3, the built-in function `open()` has an `encoding` parameter. You don't need to use `codecs.open()`. Otherwise, use `io.open()` for cross-python code :) Python 3.4.0 (default, Jun 19 2015, 14:20:21) >>> import codecs >>> codecs.open is open False >>> import io >>> io.open is open True | |
Re: I had a lot of success using [luckybackup](http://luckybackup.sourceforge.net/manual.html) instead of rsync (actually, luckybackup wraps rsync but I think it is much easier to use). You can install it with apt-get. Luckybackup comes with a GUI in which you define job profiles. So here a job profile would contain that you … | |
Re: Another classical way to have a static variable in a function in python is to add this variable as an attribute of the function: [code=python] def countcalls(): countcalls.counter += 1 print("countcalls was called %d time(s)" % countcalls.counter) countcalls.counter = 0 for i in range(5): countcalls() """ my output --> countcalls … | |
Re: Your mission is to write a program to open any text file containing a tree like this one and output a python list having the same structure as this tree for example this is a nested node but this one is more deeply nested You can add an option to … | |
Re: I don't understand why the result needs to be 1 1 3 5 8 13, as the number 2 belongs to the Fibonacci sequence https://en.wikipedia.org/wiki/Fibonacci_number . | |
Re: Instead of parsing the C code by hand, you could start from an ast produced by an existing C parser written in python: module [pycparser](https://github.com/eliben/pycparser). Here is an example, adapted from pycparser's example explore_ast.py #----------------------------------------------------------------- # see pycparser explore_ast.py for complete example #----------------------------------------------------------------- from __future__ import print_function import sys from … | |
Re: AFAIK, there is no inplace augmented assignment operator for integers in python. It means that in foo = 4 foo += 1 the second statement creates a **new** int object and assigns it to the name foo. For user defined types, the python documentation recommends to define `+=` as an … | |
Re: Start by walking the source folder with `os.walk()` for d, dirs, files in os.walk(sourcedir): print(d, dirs, files) | |
Re: I read about a python module named [SaltStack](http://docs.saltstack.com/en/latest/) yesterday. I think it can distribute commands the way you want. | |
Re: `chown` has a `-v` option, it may help. | |
Re: This function should be rewritten in a non recursive style. If the connection times out every time, it will call itself indefinitely until it reaches the recursion limit. Did you change the recursion limit ? It is very easy to write this function with a `while True` loop. | |
Re: It is very easy to write the output to a text file with io.open(textfilename, mode='w', encoding='utf-8') as ofh: ofh.write(theoutput) If you want to enter interactively a directory path to save the files, you have 2 solutions: either read the path in the console with the `input()` method or use a … | |
Re: You can write dest = self.destination_csv(filename) with open(dest, 'wt') as fh: writer = csv.writer(fh) writer.writerows(self.makerows(flatten_dict(root))) Then you need a method def destination_csv(self, filename): """Compute a destination filename from a source filename for example if filename is C:\foo\bar\baz\awesomedata.xml the result could be C:\foo\bar\baz\CSV\awesomedata.csv """ use function from module os.path and string … | |
Re: For an even better debugging experience while applying woooee's advice, use the [printat module](https://www.daniweb.com/software-development/python/code/479747/print-with-line-and-file-information) and write from printat import printat print = printat at the top of your file. | |
Re: You could use exec "f()" in {'f':f} | |
Re: Because a new total is computed at line 7. This total is never tested at line 6. What you can do is while True: total = number1 + number2 number1, number2 = number2, total if total >= 4000000: break else: numbers_list.append (total) Make sure your editor is configured to indent … | |
Re: A dictionary is created with `{}` delimiters, not `[]`. | |
Re: No problem with firefox in kubuntu. | |
Re: You can also use while playermove not in ('paper', 'scissors', 'rock'): ... | |
Re: The signature of the `bytes()` function gives the solution class bytes(object) | bytes(iterable_of_ints) -> bytes | bytes(string, encoding[, errors]) -> bytes | bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer | bytes(int) -> bytes object of size given by the parameter initialized with null bytes | bytes() -> empty bytes object ... … | |
Re: Do you really mean a distributed denial of service attack ? Where would it be funny or cool ? |
The End.