2,646 Posted Topics

Member Avatar for eman neercs

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 …

Member Avatar for eman neercs
0
5K
Member Avatar for glao

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

Member Avatar for glao
0
153
Member Avatar for Dat One Lefty

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.

Member Avatar for Dat One Lefty
0
163
Member Avatar for mizaza
Member Avatar for Athicom

You can also use `/usr/bin/pdfunite` to merge several pdf into one (in ubuntu, install package `poppler-utils` for this)

Member Avatar for Gribouillis
0
663
Member Avatar for fonzali

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 …

Member Avatar for fonzali
0
1K
Member Avatar for Tcll

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 …

Member Avatar for Tcll
0
500
Member Avatar for rufael

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.

Member Avatar for ~s.o.s~
0
537
Member Avatar for Brandon Hatch

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 …

Member Avatar for Brandon Hatch
0
2K
Member Avatar for Tcll

I only removed line 7 and it worked. Edit: You can also use this initialization NS = {'__builtins__': __builtins__}

Member Avatar for Tcll
0
543
Member Avatar for fonzali

> insert between lines 70 and 71 this I updated the code accordingly. Note that a None value must be checked with the `is` operator.

Member Avatar for fonzali
2
2K
Member Avatar for Clive_1

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')

Member Avatar for Gribouillis
0
48
Member Avatar for JohnMcPherson
Member Avatar for rubberman
0
342
Member Avatar for pritaeas
Member Avatar for Pavol

@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 …

Member Avatar for David W
0
307
Member Avatar for sajidk25

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.

Member Avatar for vegaseat
0
361
Member Avatar for Kaustav_2

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'`

Member Avatar for Gribouillis
0
1K
Member Avatar for Suzie999
Member Avatar for Dani
0
305
Member Avatar for DumbBlonde89
Member Avatar for bright.silva

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) & …

Member Avatar for megaflo
0
413
Member Avatar for mattrweaver

You could perhaps try df[...] = df[...].map(lambda x: datetime.strptime(x, '%H:%M:%S'))

Member Avatar for mattrweaver
0
4K
Member Avatar for lewashby

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.

Member Avatar for Gribouillis
0
562
Member Avatar for lewashby

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 …

Member Avatar for Gribouillis
0
474
Member Avatar for Slass33

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.

Member Avatar for megaflo
0
186
Member Avatar for Niloofar24

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'] >>>

Member Avatar for Gribouillis
0
17K
Member Avatar for DragonMastur
Member Avatar for Slass33
0
532
Member Avatar for misgee2001

It seems to me that you only need to remove lines 14 and 18 from the above program to get a start.

Member Avatar for megaflo
0
130
Member Avatar for Slass33

Remove all the `aNa` variables from this program. Use `word[N]` etc.

Member Avatar for Gribouillis
0
307
Member Avatar for lewashby

Did you read this help page https://help.ubuntu.com/community/Mount/USB ?

Member Avatar for Gribouillis
0
103
Member Avatar for Zeinab_1

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

Member Avatar for vegaseat
0
268
Member Avatar for lewashby

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 …

Member Avatar for rch1231
0
481
Member Avatar for vegaseat

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 …

Member Avatar for vegaseat
23
34K
Member Avatar for vegaseat

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 …

Member Avatar for vegaseat
20
18K
Member Avatar for Brandon500

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 .

Member Avatar for woooee
0
237
Member Avatar for DragonMastur

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 …

Member Avatar for vegaseat
0
823
Member Avatar for anumash

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 …

Member Avatar for megaflo
0
334
Member Avatar for Rajesh_18

Start by walking the source folder with `os.walk()` for d, dirs, files in os.walk(sourcedir): print(d, dirs, files)

Member Avatar for Gribouillis
0
281
Member Avatar for Pavan_6

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.

Member Avatar for Pavan_6
0
184
Member Avatar for lewashby
Member Avatar for firoj26

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.

Member Avatar for firoj26
0
365
Member Avatar for Niloofar24

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 …

Member Avatar for Gribouillis
0
373
Member Avatar for Saran_1

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 …

Member Avatar for Saran_1
0
417
Member Avatar for Henry_5

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.

Member Avatar for DragonMastur
0
801
Member Avatar for Tcll
Member Avatar for Louis_2

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 …

Member Avatar for Gribouillis
2
206
Member Avatar for Flying_robot
Member Avatar for Flying_robot
0
222
Member Avatar for ehpratah
Member Avatar for Louis_2
Member Avatar for Gribouillis
0
311
Member Avatar for Martin_8

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 ... …

Member Avatar for Gribouillis
0
5K
Member Avatar for Niloofar24

Do you really mean a distributed denial of service attack ? Where would it be funny or cool ?

Member Avatar for Niloofar24
-4
538

The End.