133 Posted Topics

Member Avatar for bhanu1225

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 …

Member Avatar for jice
0
282
Member Avatar for ning2009

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 …

Member Avatar for ning2009
0
178
Member Avatar for ning2009

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

Member Avatar for ning2009
0
212
Member Avatar for ning2009
Member Avatar for ning2009

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

Member Avatar for ning2009
0
213
Member Avatar for pythononmac
Member Avatar for pythononmac
0
684
Member Avatar for g_e_young

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

Member Avatar for g_e_young
0
129
Member Avatar for mahela007

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

Member Avatar for mahela007
0
109
Member Avatar for breatheasier

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]

Member Avatar for BearofNH
0
157
Member Avatar for drew7py

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

Member Avatar for Ene Uran
0
4K
Member Avatar for foker500

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]

Member Avatar for jice
0
159
Member Avatar for revenge2

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 …

Member Avatar for Ene Uran
0
159
Member Avatar for Aue

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]

Member Avatar for Aue
0
125
Member Avatar for dineshjaju
Member Avatar for int3grate

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 …

Member Avatar for woooee
0
289
Member Avatar for rajasekhar1242

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

Member Avatar for nikhilvishnupv
0
457
Member Avatar for Crazywu

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

Member Avatar for Stefano Mtangoo
0
774
Member Avatar for codedhands

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]

Member Avatar for jice
0
126
Member Avatar for SteveJ.

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 …

Member Avatar for jice
0
195
Member Avatar for blackcorner
Member Avatar for ZZucker
0
213
Member Avatar for paferlini

you can use the pprint module to format lists, tuples or dictionaries into readable strings...

Member Avatar for jice
0
92
Member Avatar for Stefano Mtangoo

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

Member Avatar for Stefano Mtangoo
0
133
Member Avatar for Stefano Mtangoo

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

Member Avatar for Stefano Mtangoo
0
116
Member Avatar for budstar

Please, use (code=python)(/code) tags around your code to make it readable...

Member Avatar for bumsfeld
0
101
Member Avatar for Mackjan

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 …

Member Avatar for Mackjan
0
93
Member Avatar for Kythas

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 …

Member Avatar for jice
0
134
Member Avatar for jayverene

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

Member Avatar for jayverene
0
86
Member Avatar for blue_misfit

[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) ?

Member Avatar for woooee
0
149
Member Avatar for lkk2116

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]

Member Avatar for jrcagle
0
101
Member Avatar for Roadphantom13

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]

Member Avatar for vegaseat
0
167
Member Avatar for PicoDoM
Member Avatar for PicoDoM
0
664
Member Avatar for jliu66

Hi, In python, blocks structure rely on indentation [code] while E: Bt else: Bf back to the while level [/code]

Member Avatar for Lardmeister
0
119
Member Avatar for sreejithps

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

Member Avatar for jice
0
1K

The End.