2,646 Posted Topics
Re: You can also use the `key` parameter in function `min()`: import itertools as it point_list = [ (1, 2), (3, 5), (4, 6), (1.5, 7), ] def distance(pair): p, q = pair return ((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) ** 0.5 print(min(it.combinations(point_list, 2), key = … | |
Re: Python complains because the file's `write()` method needs a string argument. Here the correct way to handle things is to find the values of the `href=` attributes, which contain the link targets. If you want to write anything to the file, you can use `write(str(anything))`. | |
Given a unicode string or file, what is the best way to find a short unicode string that is **not** a substring of the first one ? I want a working algorithm that avoids transforming the first string into a list of characters. My first idea is to choose a … | |
Re: You don't need to install it: it is part of the python standard library. Look in the standard's library documentation for reference. | |
Re: Are you really running *windows 95* ? I thought it died more than 15 years ago. You could perhaps rewrite the editor for python 1.5 (which was a very good version of python). | |
Re: Yes , you mistakenly believe that the function equals 1. The square root is in fact `sqrt((x-1)**2)` Mathematically, it has the same value as `abs(x-1)`, which is `x-1` when `x >= 1` and `1-x` when `x <= 1`. It means that your function's value is `x` when `x < 1`. | |
Re: It is the same difference as between result = [] for c in ['as', 'df']: for i in range(len(c)): result.append(c[i]) print result and result = [] for c in ['as', 'df']: result.append(c[0]) print result | |
Re: Hm, the RAR file contains two exe programs which are fired by the python program. It is probably a virus or spyware. The best thing to do is **not to run** this program. It could very well erase all your files for example. | |
Re: Well, you can use the index of the python documentation https://docs.python.org/3/genindex-all.html It could be your beginner's project: write a command line tool which tells you from which module you can import symbols. | |
Re: The problem is that there is a file `calendar.py` on the python path which shadows the builtin module calendar. The traceback says "C:/Users/palmer_a/Documents/App\calendar.py" but it should be "C:\Python34\lib\calendar.py" The solution is to rename the file` App/calendar.py` or to move it out of the python path or to remove the `App` … | |
Re: This is very similar to your previous question. Take the time to understand how the code works number = int(''.join(mylist)) | |
Re: Also have much more details from the command line with this snippet https://www.daniweb.com/software-development/python/code/478935/launch-default-editor-for-python-module- | |
Re: To empty the list, use numbers[:] = [] | |
Re: You are trying to evaluate an arithmetic expression. There are several levels of understanding of your question. 1) If you only want a working solution, you can use python's own expression evaluator: result = eval(' '.join(str(x) for x in mylist)) this is a little bit dangerous if somebody else can … | |
Re: You need a space between the two words `if` and `__name__`. | |
Re: No, not me thanks, I don't want to be famous, I prefer anonymity. Why not Woooee or Snippsat ? | |
Re: Well, let's take an example. We have a module file `foo.py` containing the code print('Hello from foo.py') Can you tell us precisely which statements should be executed and in which order ? | |
Re: epsilon has no special meaning in python. It is a valid identifier which can be used as a variable name as in the above code. In numerical analysis, epsilon is typically used to denote a positive quantity close to zero. | |
Re: These anonymous could very well be a western intelligence agency. | |
Re: Here is an example session in my terminal 15:26 atelier] ps aux | grep firefox eric 2547 1.6 7.5 1484500 305384 ? Sl 12:44 4:40 /usr/lib/firefox/firefox --sm-config-prefix /firefox-iWhUk7/ --sm-client-id 1017a158179130000142325992000000022580029 --screen 0 eric 7843 0.0 0.0 14556 928 pts/22 S+ 17:32 0:00 grep --color=auto firefox 17:32 atelier] kill -2 2547 … | |
Re: In linux, you can use `subprocess.call(['xdg-open','NAMEOFFILE'])`. | |
![]() | Re: Yes it looks like an experimental module by a [famous ruby guru](http://www.smashingmagazine.com/2010/05/15/why-a-tale-of-a-post-modern-genius/). Is it still developped ? ![]() |
Re: Open the documentation page of the [sqlite3 module](https://docs.python.org/2/library/sqlite3.html#module-sqlite3), then search all occurrences of `INSERT INTO` in this page. Your answer is there! | |
Re: You probably mean `Total.insert()` instead of `total.insert()`. Edit: Note that your `global` statements are unnecessary. `global x` is only necessary in a function if the function contains a line `x = ...` and x is a global variable. If you want to use a global variable without setting its value, … | |
Re: What are your dictionaries? Python's built-in dictionaries cannot have several occurrences of the same key. | |
Re: It is true, although I've read rumors that `file.tell()` is slow, at least in text mode. See [Click Here](http://bugs.python.org/issue11114) for example. You can also define your own wrapper def traverse_file(ifh): pos = 0 for lineno, line in enumerate(ifh, 1): tmp = len(line) yield lineno, pos, line pos += tmp with … | |
![]() | Re: Well, as 7 is in the first column and 5 is in the second column, the result is hardly suprising >>> a[:,0] array([1, 3, 6, 7]) >>> a[:,1] array([2, 4, 5, 8]) >>> 7 in a[:,0] and 5 in a[:,1] True EDIT: this seems to be working, extracting an array … ![]() |
Re: > However, if I'm asked to do an exercise, I cannot quite get every step down to what I should be doing. It is because what you should be doing is not determined solely by the problem to solve or the peculiarities of the language. The largest part is determined … | |
Re: Here is a modified version which works (with python3) up to the point where the `newWindow()` method is called. You must add the code for the popup window and subsequent behavior #-*-coding: utf8-*- from tkinter import * import tkinter class GUI: def __init__(self): self.root= Tk() self.labelVariable = StringVar() self.root.title('Projet informatique') … | |
Re: You can install sqliteman to browse the database. Type sudo apt-get install sqliteman in ubuntu or other debian distros. Then open your database file with sqliteman and examine the contents of the database. You can also run sql statements in the gui. | |
Re: Why not this ? >>> import numpy as np >>> a = np.array([1,2,1,3,4,5]) >>> 0.64 + 0.12 * a array([ 0.76, 0.88, 0.76, 1. , 1.12, 1.24]) | |
Re: For simple interfaces such as displaying or capturing data, a super easy solution is [guidata](https://pythonhosted.org/guidata/). | |
Re: You can use a breadth-first traversal to find the webapps folders first, then walk these folders import collections as col import itertools as itt import os def breadth_first(root, subnodes_func, max_depth=None): """Yield pairs (depth, node) in the breadth-first traversal of a tree Args: root: root node of the tree subnodes_func: function … | |
Re: What went wrong ? With the shebang line, it should work readily. | |
Re: You could perhaps create an image in a canvas widget, then draw other widgets above the canvas. | |
Re: In python 2 in kubuntu, I can import it directly import ttk In python 3 it is from tkinter import ttk `ttk.py` should be in the folder lib-tk in your python2 library. Try to run locate ttk in a terminal to see where it is. | |
Re: The `random` module may be helpful. | |
Re: Why don't you use the [other thread's solution](https://www.daniweb.com/software-development/python/threads/490499/problem-with-creating-a-file) ? I wrote all the code to create the file if does not exist and also to be able to run the code from another directory etc. If you use a function such as `load_favorite()` instead of `pickle.load( open("films.db", "rb"))` it will … | |
Re: I don't know much about it, but there are many links about this. This one for example looks good http://www.unixlore.net/articles/using-curl-for-ftp-over-ssl-file.html . It seems to me that you should at least try the -v option to get debugging information if it fails. | |
Re: Being able to save data to disk and retrieve it is equivalent to being able to convert this data to string and then back to data. Indeed, you can always define def save(data, filename): with open(filename, 'w') as fh: fh.write(string_from_data(data)) def retrieve(filename): with open(filename) as fh: return data_from_string(fh.read()) It means … | |
Re: As a pythonista, my first try is python -c "import subprocess as sp; sp.Popen(['/usr/bin/dolphin'])" 2>/dev/null and it works. Dolphin is launched and the terminal is not locked. You can even close the terminal. Edit: there must be a bash solution too, but I don't know it :) EDIT 2: if … | |
Re: Python says why it doesn't work Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'Tkinter' Nothing is more important than the error message! Don't forget to add it to your posts. The reason is that between python 2 and python 3, some modules … | |
Re: On my system, `man parted` shows option -l, --list lists partition layout on all block devices | |
![]() | Re: I agree with Hericles that this is an impressive but incomplete achievement. Once you know why moving that line made the difference, a very important step is to find the tools, which necessarily exist, which would have turned these five weeks of nightmare into a few hours, or a few … ![]() |
Re: You can create a pickle file containing an empty list of favorite movies #!/usr/bin/env python3 # -*-coding: utf8-*- import os import pickle # use db file in the same folder as # our program (this could be different) filename = 'films.db' folder = os.path.dirname(os.path.abspath(__file__)) filepath = os.path.join(folder, filename) if not … | |
Re: If you add lists of integers together, you will always obtain a list of integers. If you want a list of sublist, you must *append* sublists to pack: pack.append(sublist) This adds only one element, this element is a sublist. |
The End.