2,646 Posted Topics

Member Avatar for vegaseat

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

Member Avatar for gerisam
3
2K
Member Avatar for Niloofar24

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))`.

Member Avatar for Niloofar24
0
738
Member Avatar for Gribouillis

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 …

Member Avatar for Gribouillis
0
334
Member Avatar for Niloofar24

You don't need to install it: it is part of the python standard library. Look in the standard's library documentation for reference.

Member Avatar for Niloofar24
0
281
Member Avatar for DragonMastur

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

Member Avatar for DragonMastur
0
427
Member Avatar for Slyte

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

Member Avatar for Slyte
0
196
Member Avatar for bikash_2
Member Avatar for sarathsshanker

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

Member Avatar for sarathsshanker
0
373
Member Avatar for dannyb270

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.

Member Avatar for dannyb270
-1
426
Member Avatar for ZZMike

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.

Member Avatar for ZZMike
0
154
Member Avatar for Andrae

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

Member Avatar for Andrae
0
261
Member Avatar for Niloofar24

This is very similar to your previous question. Take the time to understand how the code works number = int(''.join(mylist))

Member Avatar for vegaseat
0
299
Member Avatar for vegaseat

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-

Member Avatar for Gribouillis
3
685
Member Avatar for Niloofar24
Member Avatar for Niloofar24

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 …

Member Avatar for Niloofar24
0
334
Member Avatar for php_student
Member Avatar for Gribouillis
0
43
Member Avatar for happygeek

No, not me thanks, I don't want to be famous, I prefer anonymity. Why not Woooee or Snippsat ?

Member Avatar for happygeek
0
448
Member Avatar for Tcll

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 ?

Member Avatar for Tcll
0
542
Member Avatar for MustafaScript

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.

Member Avatar for vegaseat
0
2K
Member Avatar for happygeek
Member Avatar for rushi_1

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 …

Member Avatar for rubberman
0
167
Member Avatar for Niloofar24
Member Avatar for iamthwee

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 ?

Member Avatar for iamthwee
1
424
Member Avatar for Niloofar24

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!

Member Avatar for vegaseat
0
5K
Member Avatar for Johnny Blaz

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

Member Avatar for Gribouillis
0
204
Member Avatar for giancan

What are your dictionaries? Python's built-in dictionaries cannot have several occurrences of the same key.

Member Avatar for giancan
0
239
Member Avatar for lewashby

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 …

Member Avatar for lewashby
0
204
Member Avatar for Froweey
Member Avatar for ShilohAmi

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 …

Member Avatar for ShilohAmi
0
244
Member Avatar for webmeat

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

Member Avatar for Gribouillis
0
226
Member Avatar for Farrukh saleem
Member Avatar for ShouldAt3
0
355
Member Avatar for doule

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

Member Avatar for Gribouillis
0
227
Member Avatar for amin2005
Member Avatar for HiHe
-2
116
Member Avatar for Niloofar24

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.

Member Avatar for HiHe
0
313
Member Avatar for Afi83

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

Member Avatar for Gribouillis
0
600
Member Avatar for Niloofar24

For simple interfaces such as displaying or capturing data, a super easy solution is [guidata](https://pythonhosted.org/guidata/).

Member Avatar for vegaseat
0
844
Member Avatar for huskeraider

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 …

Member Avatar for Gribouillis
0
286
Member Avatar for Niloofar24
Member Avatar for Niloofar24

You could perhaps create an image in a canvas widget, then draw other widgets above the canvas.

Member Avatar for HiHe
0
50K
Member Avatar for Niloofar24

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.

Member Avatar for Gribouillis
0
12K
Member Avatar for Niloofar24
Member Avatar for Niloofar24

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 …

Member Avatar for Niloofar24
0
258
Member Avatar for tiredoy

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.

Member Avatar for Gribouillis
0
246
Member Avatar for Niloofar24

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 …

Member Avatar for snippsat
0
5K
Member Avatar for RikTelner

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 …

Member Avatar for JasonHippy
0
289
Member Avatar for Niloofar24

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 …

Member Avatar for Niloofar24
0
10K
Member Avatar for fiddler80

On my system, `man parted` shows option -l, --list lists partition layout on all block devices

Member Avatar for fiddler80
0
336
Member Avatar for DaniWebUser_1

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 …

Member Avatar for DaniWebUser_1
0
581
Member Avatar for Niloofar24

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 …

Member Avatar for Niloofar24
0
2K
Member Avatar for kouty

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.

Member Avatar for sneekula
0
206

The End.