133 Posted Topics
Re: could you put tags aroud your code, please ? [ code=python] your code here [ /code] 2d point, I don't understand what you are doing [QUOTE] ip = 8 while(ip <= 9): cxn1 = MySQLdb.connect(host='10.0.2.9',host='192.168.1.2', db='navicat') cur1 = cxn1.cursor() cxn = MySQLdb.connect(user='root',db='navicat') cur = cxn.cursor() [/QUOTE] You don't use ip … | |
Re: I thought of your problem this WE and wrote a solution. I see other people have answered but I post mine as it is written anyway. It will give you another way to solve your problem in the same idea i gave to your other post. [code=python] lines=["1 J=2,7183 SEC=CON450X450 … | |
Re: [QUOTE=ning2009;840585]Hi, I used a stupid code below [code=python] i=0 for line99 in alllines: i=i+1 if "LOAD" in line99: print "Line number is", i break [/code] to achieve line number. Any better code? Thanks. ning[/QUOTE] You can do (here, i imagine that you did something like alllines = a_file.readlines() ): [code=python] … | |
Re: you inverted targetlines[1] and targetlines[2] | |
Re: [code=python] import math # First of all, Frame_Section should contain the following. Otherwise, you'll have # to seach for your elements in the lists # for elt in list: # if elt[0]='MAT': # result=elt[1] # This way is far better Frame_Section={'CON450X450': {'MAT':'CONC2', 'SH':'R', 'T':'.45,.45'}, 'B400': {'MAT':'CONC2', 'SH':'R', 'T':'.16,.4'}, 'FSEC1': {'MAT':'CON3', … | |
Re: [QUOTE=pythononmac;818552]name = caffé print name [/QUOTE] Don't you mean : name="caffé" | |
Re: Here is a way to store your result in a list. [CODE=python] data = open ("files/" + data + ".txt", 'r') file_list=[] for line in data: print line file_list.append(line[34:38]) [/CODE] Just one point : instead of "line[34:38]" which is dangerous in this kind of csv files, you can use : … | |
Re: [QUOTE=mahela007;811292]I am programming a folder synchronizer for my first python project. (I want to get it finished before school starts in about 2 months. heh heh) Anyway, up till now my synchronizer will only copy file from one folder to another. I want it to be able to copy entire … | |
Re: to know the index of a list element in a for loop you can try: [CODE=python] for i, element in enumerate(['a', 'b', 'c', 'd']): print i, element # Result 0 a 1 b 2 c 3 d [/CODE] | |
Re: [QUOTE=Ene Uran;799572]As long as there is no comma in your individual data elements, you can use function join() and replace() in this manner: [code=python]q = ['23', 'CL', '006', '2004', 'DBA8ORPU', '41', '8Y', '0', 'S0111P', '2'] s = ",".join(q).replace(",", " ") print(s) """ my result --> 23 CL 006 2004 DBA8ORPU … | |
Re: To read and write dbf files, try the dbfpy module : [url]http://www.fiby.at/dbfpy/[/url] A snippet example : [url]http://code.activestate.com/recipes/362715/[/url] | |
Re: For line count, it is very easy (this is to be put after your own code) : [code=python] f = open ('out.txt', 'w') for i, l in enumerate(file('site.txt', 'r')): if i > 10: f.write(l) [/code] To delete part of the text, you can use regexp (this example erase the body … | |
Re: With XnView (or any other software that provide this functionality) If you want to do it with python, I suggest PIL : [url]http://www.pythonware.com/products/pil/[/url] You should have a look at this : [url]http://www.pythonware.com/library/pil/handbook/pilconvert.htm[/url] | |
| |
Re: Why don't you use the second parameter of the seek function ? From [url]http://docs.python.org/library/stdtypes.html#file-objects[/url] : [QUOTE]file.seek(offset[, whence])¶ Set the file’s current position, like stdio‘s fseek. The whence argument is optional and defaults to os.SEEK_SET or 0 (absolute file positioning); other values are os.SEEK_CUR or 1 (seek relative to the current … | |
Re: Do you use W$ or Linux ? Where did you install the mySqlDb module ? Is it in your site-package directory ? Can you see this directory in your sys.path (in Idle : "File>path Browser") | |
Re: You can use the tkFileDialog module [url]http://epydoc.sourceforge.net/stdlib/tkFileDialog-module.html[/url] Example : [code=python] # -*- coding: iso-8859-1 -*- import tkFileDialog from Tkinter import * class openDialog(Frame): def __init__(self, master=None): self.root=master self.createWidgets() def createWidgets(self): """ Create widgets """ self.fFrame = Frame(self.root) self.svDir = StringVar() self.eDir = Entry(self.fFrame, width=70, textvariable=self.svDir) self.eDir.pack() self.bSelDir = Button(self.fFrame, text="askdir") … | |
Re: You should use "*?" instead of "*" : * will take the longest string that match the pattern while *? will take the shortest. [highlight="python"]p=re.compile(r'\b(href="(.*?)"){1}\b')[/highlight] | |
Re: You can use the csv module : [URL="http://docs.python.org/library/csv.html"]http://docs.python.org/library/csv.html[/URL] or, as your case is simple, do it yourself : [CODE=python] f=open('myfile.txt','r') # Opens the file read only d={} # Dict to store result for line in f: # For each line of the file sline=line.rstrip('\n').split(" | ") # split the line … | |
Re: You can use regexp (re module) instead of string module for that. | |
Re: you can use the pprint module to format lists, tuples or dictionaries into readable strings... | |
Re: Here is a couple of tutos about python and mysql [url]http://www.devshed.com/c/a/Python/Database-Programming-in-Python-Accessing-MySQL/[/url] [url]http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/[/url] enjoy | |
Re: [QUOTE=evstevemd;674747]Can you rewite the code and put here so that I will understand what you are saying! By the way thanks for response Steve[/QUOTE] [CODE] # SMD Inc since 2003.py import wx ID_ABOUT = 100 ID_PRINT = 101 ID_EXIT =102 class MainWindow(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, … | |
Re: Please, use (code=python)(/code) tags around your code to make it readable... | |
Re: In your code : 1. when a and b are outside ]1, 53[, you do nothing except looping while true (infinite loop) - look at indentation. 2. If 1<a<b, you don't control if b is allright. You immediately break the loop [code=python] def lasin (): a=int( input ("Put in a … | |
Re: I'm not sure it is required to sort the lists. You may proceed just as woooee says about soring keys in lists and then simply test "if not key in list". Something like (i just do 1 list here to be simple) [code=python] alreadyStored=[] for line in file(filename): if not … | |
Re: could you please wrap your code between [ code=python] [ /code] tags. Indent is very important in python and not doing this makes your code unreadable. thx | |
Re: [QUOTE=blue_misfit;576545] I know, its ugly :) I'm no programmer. It's complaining about line 26, which is: if fnmatch.fnmatch(filename, '*.vob'): [/QUOTE] And what does he say (Which exception is thrown) ? | |
Re: You should look at the functions os.walk or os.path.walk (modules os and os.walk) which explore a tree and let you do what you want with the files. Maybe os.walk is easier to use... see [url]http://docs.python.org/lib/os-file-dir.html[/url] [url]http://docs.python.org/lib/module-os.path.html[/url] | |
Re: You should look at Tkinter (available in the normal python distrib) - It would be much simpler than reinvent the wheel. [url]http://www.ferg.org/thinking_in_tkinter/index.html[/url] | |
Re: test = u"\u2022" print test.encode("utf-8") ÔÇó Have you tested this one ? | |
Re: Hi, In python, blocks structure rely on indentation [code] while E: Bt else: Bf back to the while level [/code] | |
Re: You can do something like [CODE] for myCommand in myCommandList: try: self.conn.telnet(myCommand) # I don't know the exact syntax # but you'll know that easily except theTelnetExceptionRaised: self.conn = telnetlib.Telnet(so.telnetHost, so.telnetPort) [/CODE] This should work ok |
The End.