15,194 Topics
![]() | |
(a | b): For what I have read in other forum post, if a is true, python doesn't evaluate b an returns a. (a & b): What happens with logical and? If a is false, does python evaluates b or not? Thanks for your help. | |
The "exec" function seems to literally execute strings as code in a Python shell: >>> exec("a=2") >>> a 2 >>> However, when I tried this function from within a tkinter form, the variables were no longer accessible via their original names: a=1 #initialize the variable "a" exec(str(CodeTextBox.get())) # I entered … | |
Hi I am developing a spell checker for my language, and I came across solving an interesing problem. It would be great if you can suggest me an optimized solution for the problem described below: I have certain group of letters like these: Group #1: c,r,b Group #2: a,z,k Group … | |
[code=python] class ExcelDocument(): """ Some convenience methods for Excel documents accessed through COM. """ def __init__(self, visible=True): self.app = Dispatch("Excel.Application") self.app.Visible = visible self.sheet = 1 def new(self, filename=None): """ Create a new Excel workbook. If 'filename' specified, use the file as a template. """ self.app.Workbooks.Add(filename) def open(self, filename): """ … | |
I don't want to disturb you, but I don't understand how works the properties. I mean, using this simple code: #!/usr/bin/env python2.6 def cosas(self, width): return "cosas" class Rect(object): def __init__(self, width, height): self.width = width self.height = height self.area = 0 print "Adios" @property def _area(self): return self.width * … | |
My program doesn't make it pass these lines on one computer: [code] import re, os, glob, time os.chdir('/Software/xampp/htdocs/catalog/temp') file_list = glob.glob('Full-EP*.txt') file_dict = dict([(os.stat(a_file).st_mtime, a_file) for a_file in file_list]) date_list = list([key for key, value in file_dict.items()]) s = file_dict[max(date_list)] datePattern = re.compile(r'^Full-EP(\d{4})(\D{3})(\d{2})-(\d{2})(\d{2}).txt$') webdate = datePattern.search(s).groups() metadata = os.stat('WEB-Price-List.txt') dbdate … | |
I have read a little bit on XML and I will need it to get some information from already available XML files. I would like to learn it by making very small playlist. However I have encountered the two beasts. I don't know much of XML, especially with python. So … | |
hello im not very experienced with python so sorry for any bad code i am running ubuntu 8.10 and using pyserial i have made a script that reads the serial input from an arduino if you are not familier with an arduino here is there website [URL="http://www.arduino.cc/"]http://www.arduino.cc/[/URL] for some reason … | |
Hi, all Is there a way to get strings line by line from tk Text box? I know there is readline for files, but i don't see anything like that for tk Text box. Only thing i see is text.get(float(index1), float(index2)) but it seems unhelpful in my case, although it … | |
![]() | Hey guys, I have already worked on a program which uses threads, but today I just wanted to work on threading, and only threading: [code=python] import threading class first_time(threading.Thread): def print_first_time(self): print("What is your name?") for x in range(1000): first_time().start() [/code] But, the problem is, nothing happens! Why is it … |
Hi, I'll try and explain my problem as simple as possible. I have written a module to perform a generalised operation (as shown below). [code] from math import sqrt from math import pow from math import log10 from Numeric import * import numpy as np def Entropy(parameters, temperature): t=float(temperature/1000.0) return … | |
Hi, I am new in Daniweb. I am trying to do a simple task in Python but cannot figure out how it works. Keeps getting it wrong. Basically, I have a main GUI class App which has 2 entry boxes where you fill two numbers, a listbox where the results … | |
[CODE] def find_and_sep(inputstr, thing_to_find): #thing to find is a string that is a regular expression #finds thing_to_find and returns tuple of the rest (before, thing, after) inputstr.strip() #match it m=re.match(thing_to_find, inputstr) #match first instance if(m==None): return "" start = inputstr[:m.start()] mid = inputstr[m.start():m.end()] end = inputstr[m.end():] tuple_x = start,mid,end return … ![]() | |
Hey guys, I need some help with Python (obviously). I need python to insert a space. I have: [CODE]name = raw_input('Enter your name? ') # prompt and read user's name [/CODE] and that works, and it asks me for a name, and insert it, then i got: [CODE]print 'Hello ' … | |
Ok, I really hated to resort to threading, but it seems like I have no other choice. I am writing a client script for the "instant message" server I just finished writing. Sadly, I am having a slight problem with threading. What I would like to do is have two … | |
Hi all, I'm trying to mimic an html form that calls a script on the web. When I put the form together on a page, it works, and I was wondering if there was a way I could "scrape" this post request and see what I'm missing when I try … | |
Hello, I'm working on a new little project that moniters a configuration file. Everything seems to work great except for when I attempt to do some error handling. The configuration file simply looks like this. # third sets the lights # 0 = off, 1 = on, 3 = lights … | |
So I want to make a program that allows me to press a key (for example a). So when I press a, I want it to type(right term?) a predefined string (abcdefghijklmnopqrstuvwxyz for example). Like once the program is complete, I could go into notepad and press a and it … | |
Hello! I have a little problem. I have to print a table (four columns from an Excel file) in a text box. I took a string and I kept appending all the cells from the file that interested me and I used the textbox provided by easygui. [CODE]textbox(msg='', title=' ', … | |
Hi, I'm a newbie to python and I'm reading a file and trying to split a string every 3 spaces, that is included any whitespace. string.split() will split the string up every whitespace, but is there another way to specify every 3 spaces, whether there is whitespace or not? I'm … | |
Hi, I have slogged my way through, Mark Lutz's Learning Python it is a great book but the problem I have with it is that it doesn't have any practical programing question like the dietel books. Can you guys please tell me a few books with questions that follow the … | |
hi, i just start to learn and doing programming with python (was an old timer programmer in other languages). when i saw a project idea about creating your own squareroot function, i tried it. the problem start was when i try to compare the result of x**2 where x is … | |
I cannot get the code work. I want to use placeholder than a fixed value. When use fixed value it works but not placeholder. Please correct me! [CODE=python] import sqlite3 as sql class Tables(object): def __init__(self): print "Class created!" def CreateDb(self, dbname): self.conn = sql.connect("?", (dbname, )) self.cur = self.conn.cursor() … | |
Hi, I'm trying to run a batch of commands from a .txt file using python. ("cmd.batch.txt" = ~1000 command lines : perl cmd.1.pl -in -parameters) and redirect renamed output files to new folders. It works fine for the first line, but I'm having trouble getting something to loop through all … | |
Hello, I am trying to make a GUI interface for a plotting routine written with matplotlib. The GUI is in PyGtk. One of the things I would like to have is a cross hair through the mouse cursor (a vertical and horizontal line intersecting at the mouse) which moves along … | |
Hey all, Here's my problem: I have a class that I want to be able to save and and load. But I need the class to be mutable I guess. Check it out: [CODE=python]class Tool: def __init__(self,name,function): self.name = name self.function = function self.savename = self.name + '.txt' def save(self): … | |
My question is : How to sort files by name and delete in Python. What i want and mean is: In TextFolder have: a1.txt a2.txt a3.txt a4.txt a5.txt a6.txt a7.txt a8.txt a9.txt a10.txt i wan sort the file by name and i only wan keep 10 files only in the … | |
[CODE=python] import sqlite3 as sql class Tables(object): def __init__(self): print "Class created!" def CreateDb(self, dbname): self.conn = sql.connect("?", (dbname, )) self.cur = self.conn.cursor() def CreateNewTable(self, tablename):#, tablename self.cur.execute("CREATE TABLE IF NOT EXISTS ?(id INTEGER, name TEXT)", (tablename, )) listed = [(1, "Mary"), (2, "Martha"), (3, "Jesca"), (4, "Don")] for i … | |
I need help with writing a program that asks the user to enter distance in kilometers and then converts distance to miles | |
I appologize for the length of this post, but I have no clue what is wrong with my program. As an experiment, I wrote a XOR encryption program. It isnt very fast, but it works. Apparently, only for strings. I implemented a file encryption function, and it seems that some … |
The End.