2,646 Posted Topics

Member Avatar for EnglishInfix

The problem is that due to the assignment statement at line 34, `dealer_num` becomes a local variable in `nowviewing()`. It means that it is a different variable with the same name. The solution is to add the line `global dealer_num` at the *beginning* of `nowviewing()` to tell python that this …

Member Avatar for EnglishInfix
0
3K
Member Avatar for ZZucker

Hm, `os.listdir()` returns names, one probably needs filenames = [os.path.join(directory, name) for name in os.listdir(directory) if name.endswith(('.py', '.txt'))]

Member Avatar for snippsat
0
519
Member Avatar for satroan
Member Avatar for ZZucker
0
291
Member Avatar for Gribouillis

This small script named `sourcecode.py` is a command line tool to open a python module's source file with the default editor. For example the line $ python sourcecode.py xml.dom.minidom opens the file minidom.py from the python distribution with the default editor. The same works with user-defined modules having a python …

2
636
Member Avatar for danae.gordon9
Member Avatar for Gribouillis

This snippet shows how to find the complex roots of a polynomial using python (tested with python 2.6). You need the scipy or numpy module.

Member Avatar for Gribouillis
2
3K
Member Avatar for aanchal_1

Add print(type(variable)) # this can be useful too print(variable.__class__) there is also import inspect print(inspect.getmro(variable.__class__)) to get the ancestor classes.

Member Avatar for aanchal_1
0
258
Member Avatar for alagez

It may help everybody to know that this code is an [example](http://pythonhosted.org/neurolab/ex_newff.html) in module neurolab source code, which illustrates the use of the Feed Forward Multilayer Perceptron.

Member Avatar for alagez
0
576
Member Avatar for Gribouillis

This script computes the formal series expansion of a mathematical function on the command line using the python module swiginac, an interface to the CAS Ginac. Typical invocation in a linux terminal looks like $ serexp.py -n 7 "log(1+x)*(1+x+x**2)**(-1)" 1*x+(-3/2)*x**2+5/6*x**3+5/12*x**4+(-21/20)*x**5+7/15*x**6+Order(x**7) As far as I know, swiginac does not work in …

1
487
Member Avatar for flebber

You can define a function to do the same easily @post_process(list) def gather(xml_doc, paths): for p in paths: node = xml_doc for word in p: node = getitem(node, word) yield node a = gather(xml_doc, (('meeting', '@id'), ('meeting', '@venue'))) `post_process` is defined in [this code snippet](http://www.daniweb.com/software-development/python/code/374530/post-process-generated-values-with-a-decorator) (very useful bit).

Member Avatar for Gribouillis
0
1K
Member Avatar for Gribouillis

A simple way to resize an image programmatically, using the PythonMagick module. This module is a python port of the [the magick++ library](http://www.imagemagick.org/Magick++/).

Member Avatar for Gribouillis
4
3K
Member Avatar for anestistsoukalis

If you only changed the file `.bashrc`, why don't you simply restore the backup to see if it works ?

Member Avatar for Gribouillis
0
2K
Member Avatar for Diego_4

Think about how to evaluate the list [5, 1, 2, '+', 4, '*', '+', 3, '-'] The `evaluate_list()` function must return 14.

Member Avatar for Gribouillis
0
82
Member Avatar for javaxoty

A way I know is to distribute using setuptools in [development mode](https://pythonhosted.org/setuptools/setuptools.html#develop-deploy-the-project-source-in-development-mode). Use the command python setup.py develop in the development directory and you can edit the module indefinitely.

Member Avatar for Gribouillis
0
242
Member Avatar for saimadanmohan

The function `get_inverse_dict()` currently returns `None`. After you insert your code, it is supposed to return the dictionary {'a': 'z', 'c': 'x', 'b': 'y', 'e': 'v', 'd': 'w', 'g': 't', 'f': 'u', 'i': 'r', 'h': 's', 'k': 'p', 'j': 'q', 'm': 'n', 'l': 'o', 'o': 'l', 'n': 'm', 'q': 'j', …

Member Avatar for saimadanmohan
0
348
Member Avatar for krystosan
Member Avatar for Fighter01

I would suggest using a user friendly python application such as [cherrytree](http://www.giuspen.com/cherrytree/). Each recipe could go in a separate node of the tree, wich could be organised like a cookbook. The other part of it is that cherrytree keeps the node contents in a sqlite database where data can easily …

Member Avatar for Fighter01
0
534
Member Avatar for Afroula

Perhaps play with the [.next_siblings](http://www.crummy.com/software/BeautifulSoup/bs4/doc/#next-siblings-and-previous-siblings) and `.sibling` attributes of the title tag.

Member Avatar for Afroula
0
2K
Member Avatar for abaddon2031

If you are looking for http requests in python, the [requests](https://pypi.python.org/pypi/requests) module should provide the necessary tools. Otherwise, there is a [pycurl](http://pycurl.sourceforge.net/) ...

Member Avatar for abaddon2031
0
305
Member Avatar for tony75

This is a typical use case for generators and tools for iterables. Instead of writing to a file, use a generator import os import xml.etree.ElementTree as ET from itertools import ifilterfalse def generate_lines(): tree = ET.parse("Logfile.xml") root = tree.getroot() for element in root.iter('Path'): file_name = os.path.basename(element.text) #.exe just an example …

Member Avatar for tony75
0
1K
Member Avatar for abaddon2031
Member Avatar for abaddon2031
0
428
Member Avatar for Diego_4
Member Avatar for varshaholla

Read the doc ! [Apparently](http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#cv2.imread) `cv2.imread()` expects a filename.

Member Avatar for vegaseat
0
890
Member Avatar for nouth

> but .read() just prints the file contents not its binary What do you mean exactly ? Give a binary example (you can attach a zip or an image to a post). `read()` does not print anything, it reads the binary file's content. Please explain what you're expecting and what …

Member Avatar for nouth
0
721
Member Avatar for varshaholla

Use one of vegaseat's tkinter [examples](http://www.daniweb.com/software-development/python/code/467528/show-internet-image-with-tkinter). You can adapt the example by reading the file from your disk instead of the internet.

Member Avatar for varshaholla
0
336
Member Avatar for asadmoosvi

Here is a long [video tutorial](https://www.youtube.com/watch?v=iyXyxvs-544) about this.

Member Avatar for vegaseat
0
325
Member Avatar for tony75

I'm using kubuntu, but it should work in debian: make sure you have the development packages for python (python-dev and libpython-dev): sudo aptitude search python-dev # then may be sudo aptitude install python-dev sudo aptitude install libpython-dev sudo aptitude install python-setuptools sudo aptitude install python-pip Then sudo pip install pycrypto …

Member Avatar for tony75
0
16K
Member Avatar for knan

Use list comprehensions and [icode]sorted[/icode] [code=python] >>> dict1={'12':['123','187','1860','4821','7000','9000'],'18':['1234','4000']} >>> L = sorted((int(k), sorted(int(x) for x in v)) for k, v in dict1.items()) >>> print L [(12, [123, 187, 1860, 4821, 7000, 9000]), (18, [1234, 4000])] >>> M = [(k, x) for k, v in L for x in v] >>> …

Member Avatar for grantjenks
0
813
Member Avatar for PC
Member Avatar for John A.

You can improve the program by using the standard module `cmd` which purpose is to write interactive command line interpreters. I wrote an enhanced class of cmd.Cmd in [this code snippet](http://www.daniweb.com/software-development/python/code/258640/enhanced-cmd-class-for-command-line-interpreters). It makes it very easy to write an interpreter: copy the class ExampleCmd at the end of the file …

Member Avatar for Gribouillis
0
400
Member Avatar for trade19

A hint: >>> line = '14 18 35 47 54 - 57\n' >>> line.split() ['14', '18', '35', '47', '54', '-', '57']

Member Avatar for trade19
0
410
Member Avatar for navi2582

Try to use [this command class](http://www.daniweb.com/software-development/python/code/257449/a-command-class-to-run-shell-commands) instead of `subprocess.call()` com = Command(scriptPath).run() print(com.output) print(com.error)

Member Avatar for Gribouillis
0
444
Member Avatar for sruthiashok
Member Avatar for begueradj

I see 2 solutions 1. You wait until python 3.4 is the packaged python 3 version in your linux distro (this is currently python 3.3.2+ in my kubuntu). 2. You download the source tarball and you compile it yourself, using something like 'configure' and 'make altinstall'. There may be dependencies …

Member Avatar for begueradj
0
411
Member Avatar for BadManSam

Here is a very simple example using the microframework [bottle](http://bottlepy.org/docs/0.11/tutorial.html) (install with pip for example) # -*-coding: utf8-*- # webrobot.py from bottle import get, post, request from bottle import route, run @get('/movearm') def movearm_form(): return '''<form method="POST" action="/movearm"> Move the arm <input type="submit"/> </form>''' @post('/movearm') def movearm_submit(): from robotprogram import …

Member Avatar for BadManSam
0
486
Member Avatar for ZJRG.1997

Use the format method. Here are the different ways to print a floating number centered in a field of length 10, with precision of 2 digits >>> s = "{val:^10.2e}{val:^10.2E}{val:^10.2f}{val:^10.2F}{val:^10.2g}{val:^10.2G}{val:^10.2n}{val:^10.2%}" >>> print(s.format(val = 0.1)) 1.00e-01 1.00E-01 0.10 0.10 0.1 0.1 0.1 10.00%

Member Avatar for Gribouillis
0
217
Member Avatar for ZJRG.1997

>>> s = set(range(10)) >>> s set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> s -= set([3,4,5]) >>> s set([0, 1, 2, 6, 7, 8, 9]) >>> s -= set(range(3,10)) >>> s set([0, 1, 2])

Member Avatar for Gribouillis
0
403
Member Avatar for katharnakh

Please don't revive 6 years old threads. Also this thread is about python's tkinter. It is not at all related te asp.net or jquery.

Member Avatar for Gribouillis
0
2K
Member Avatar for Rebecca_2

The answer is yes it is possible to create *global* variables this way, but it is considered _poor_ programming. Here is this forbidden fruit globals().update((name, 'foo') for name in list1) Now all the variables exist, with value the string "foo". Apart from this bad way to do it there are …

Member Avatar for Gribouillis
0
207
Member Avatar for mark103

To make it short, I think you are doing this with dict `channels` D = {} for i in range(5): D[i] = "v%d" % i for D_key in D: print D[D_key], """ my output --> v0 v0 v1 v0 v1 v2 v0 v1 v2 v3 v0 v1 v2 v3 v4 …

Member Avatar for mark103
0
319
Member Avatar for kangarooblood

I suggest to read expressions and use lambda to create a python function deriv = input("Y' = ") # enter for example 2 * x func = eval("lambda x: " + deriv.strip()) # now func(3.7) --> 7.4

Member Avatar for rrashkin
0
367
Member Avatar for Opsive

> According to > mktime takes struct_time in local time as per > "Use the following functions to convert between time representations:" section of the page As Opsive wrote 10 posts 5 years ago, we guess that (s)he is not waiting for an answer today. Please don't revive old threads. …

Member Avatar for Gribouillis
0
913
Member Avatar for foshan

Apparently it comes from tutors at python.org 7 years ago. Read [this mail](https://mail.python.org/pipermail/tutor/2007-April/053825.html).

Member Avatar for foshan
0
217
Member Avatar for Gribouillis

My old hard drive with Linux Mint 15 Olivia refused to boot yesterday: kernel panic etc. I tried to repair the file system and now some shared libraries are missing. On this computer, I have a brand new second hard drive with Kubuntu 13.10 freshly installed. From this OS, I can …

Member Avatar for Gribouillis
0
345
Member Avatar for Dineshchitta

> will exit your program after 5 seconds This fails, but using `os._exit(0)` works, instead of `sys.exit(0)`. In my linux system, the following also works, which is very nice import thread import threading threading.Timer(2.0, lambda : thread.interrupt_main()).start() try: while True: print("stopme") except KeyboardInterrupt: print("We're interrupted: performing cleanup action.") """ my …

Member Avatar for Gribouillis
0
278
Member Avatar for Wilever

You can start by writing pseudo-code to describe the different things that your program must do # print a message saying that the following table # displays temperatures in celsius and their # conversion to farenheit. Your-code-here # set the celsius temperature C to zero Your-code-here # while the celsius …

Member Avatar for Greg_4
0
16K
Member Avatar for raju_6

Install an ssh server in the remote host and use module paramiko. [This post](http://www.daniweb.com/software-development/python/threads/375262/running-a-file-on-a-remote-computer-using-python#post1615004) is a little old, but it could help.

Member Avatar for raju_6
0
1K
Member Avatar for rajeshwari_ib

I would try sql = 'SELECT `blob_field` FROM `Tab1`' cursor.execute(sql) for row in cursor: blob_value = row[0]

Member Avatar for Gribouillis
0
2K
Member Avatar for trade19

Here is the code, reindented with tim peter's [reindent](https://pypi.python.org/pypi/Reindent/0.1.0) (not sure it would work without python 2) from tkinter import* import sys, random, tkinter ticket_price = 2 i=0 total = 0 def calculatetotals(): valid = set('12345') ticket_entry = tik.get() if ticket_entry not in valid: print('We permit values in {}.'.format(valid)) label4 …

Member Avatar for trade19
0
270
Member Avatar for brett.warren.1612

Apparently, the stream `sys.stdin` was closed when your program attempted to read a line. In which context did you run the program ? Which OS first ? was it in a python IDE ? was it in a terminal ? Did you type a CTRL D in a terminal while …

Member Avatar for brett.warren.1612
0
214

The End.