jice 53 Posting Whiz in Training
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', 'SH':'P', 'T':'.3048'},
        'B400H': {'MAT':'CONC2', 'SH':'R', 'T':'.16,.4'},
        'B200': {'MAT':'CONC2', 'SH':'R', 'T':'.16,.2'},
        'B300': {'MAT':'CONC2', 'SH':'R', 'T':'.16,.3'}}

resline="56 J=7224,164 SEC=CON450X450 ANG=45"
targetlines=["*beam section,section=R, elset=%s,material=%s",
             "%s",
             "%f, %f"]
dResult={}
# Store your resline elements in a dictionary
# 1st we split using the spaces
for elt in resline.split():
    keyValue=elt.split("=") # We separate the key from the value 
                            # and store them in a tempo list
    if len(keyValue)==2:
        dResult[keyValue[0]]=keyValue[1]
try:
    mat=Frame_Section[dResult['SEC']]['MAT'] # we get the MAT value
    # And the T values
    T=Frame_Section[dResult['SEC']]['T'].replace(".","0.") # To be simple,
                        # I do as if your floats always begin with a "." (less than 1)
    resultlines=[targetlines[0] % (dResult['SEC'], mat),
                 targetlines[1] % T,
                 targetlines[2] % (math.sin(float(dResult['ANG'])*math.pi/180), math.cos(float(dResult['ANG'])*math.pi/180))]
except KeyError:
    print "%s doesn't exist" % dResult['SEC']

for line in resultlines:
    print line
jice 53 Posting Whiz in Training

name = caffé
print name

Don't you mean :
name="caffé"

jice 53 Posting Whiz in Training

Here is a way to store your result in a list.

data = open ("files/" + data + ".txt", 'r')
file_list=[]
for line in data:
    print line
    file_list.append(line[34:38])

Just one point :
instead of "line[34:38]" which is dangerous in this kind of csv files, you can use :

file_list.append(line.split(",")[5][0:2])

This splits your line in a list, using "," as the splitting marker, takes the 5th element and takes the 2 first characters.
You can even do

file_list.append(line.split(",")[5].split(".")[0])

But if you have some more complex processes to do, yuou should have a look at the csv module...

jice 53 Posting Whiz in Training
jice 53 Posting Whiz in Training

For line count, it is very easy (this is to be put after your own code) :

f = open ('out.txt', 'w')
for i, l in enumerate(file('site.txt', 'r')):
    if i > 10:
        f.write(l)

To delete part of the text, you can use regexp (this example erase the body part) :

import re
pat=re.compile("<body.*</body>", re.DOTALL) # re.DOTALL is to include \n
f = open ('out2.txt', 'w')
f.write(pat.sub("", text_file_read))
f.close()

You can also get the content of the part this way (have a look at the re module)

You can also parse your file but if you don't have any condition on the content to erase a part, it may be simpler to do this this way :)

To parse html files, you can use the HTMLParser module
For xml or xhtml files, you can use xml.sax or xml.dom modules

jice 53 Posting Whiz in Training

With XnView (or any other software that provide this functionality)

If you want to do it with python, I suggest PIL :
http://www.pythonware.com/products/pil/
You should have a look at this :
http://www.pythonware.com/library/pil/handbook/pilconvert.htm

jice 53 Posting Whiz in Training
jice 53 Posting Whiz in Training

Can you rewite the code and put here so that I will understand what you are saying! By the way thanks for response
Steve

# 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, title, size=(500, 350))
        self.CreateStatusBar()
        self.SetStatusText("Displays program Information")
        
        menubar = wx.MenuBar()
        # File menu
        filemenu = wx.Menu()
        filemenu.Append(ID_PRINT, "&Print", "Print the current Window")
        filemenu.Append(ID_EXIT, "E&xit", "Exit the program")
        menubar.Append(filemenu, "&File")
        # Help Menu
        helpmenu = wx.Menu()
        helpmenu.Append(ID_ABOUT, "&File", "About this program")
        menubar.Append(helpmenu, "He&lp")

        # Attach and set Menubar on Frame
        self.SetMenuBar(menubar)

        # Binding Events
        self.Bind(wx.EVT_MENU, self.OnPrint, ID_PRINT)      
        
       

        self.Centre()
        self.Show(True)

    # Setting methods
    def OnPrint(self, event):
        self.close()
        dia = wx.MessageDialog(self, "Thank you!", "About the program", wx.OK)
        dia.ShowModal()
        dia.Destroy()      
        
app = wx.App()
MainWindow(None, -1, "Elijah's SMD Inc. since 2003")
app.MainLoop()
jice 53 Posting Whiz in Training

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

jice 53 Posting Whiz in Training

Sorry if this is explained too fast.

About dictionaries.
A dictionary is a type which variables are built like this
dict={"key1":"value1", "key2":"value2,...}
Keys and values can be whatever you want.
each key is unique and you can recall a value like this
value=dict["key1"]

So, to be sure you haven't any duplicate, you can create a dictionary that has your lines as keys :
dict[line]=None (or whatever you want, we only use it for the keys).

Before creating this new record, you can test if the key already exists by using dict.has_key(line)
If this returns True, the key exists so you have already processed a line like this.

for line in listLines:
    if not dict.has_key(line): # We test if the line is processed
        generateSQLStatement()
        dict[line]=''   # We say that this line is processed.

That's all. But anyway, if your solution is OK...

jice 53 Posting Whiz in Training

You don't need the insert statement, only the line...

@woooee : The key in list may not be the fastest but (just as you do for your sorting) if you cut the list in a dictionnary of 1000 lists
something like (very simple sample) :

import String

dict={}
for i in range(1000):
    dict[String.zfill(i,3)]=[]  # to fill with 0 (001)
for line in file(filename):
    if not (line in dict[line[x:x+3]):   # x points somewhere in the line where you are waiting 3 following numbers
        generateSQLStatement()
        dict[line[x:x+3]].append(line)

then, you only have to search ONE list.
When you sort, you have to sort all the lists...
I'm not sure this is better than sorting, i didn't make tests, but this is certainly simpler to write if you have to write your own sorting algorithm ;)
This may not be the best solution, I agree. In fact, i don't have very often to deal with this kind of problems...

Anyway, about the dictionary (probably faster anyway), you have have at least 2 or 3 ways to do it.
The simplest (i don't know if it is the most efficient) may be :

dict={}
for line in file(filename):
    if not dict.has_key(line):
        generateSQLStatement()
        dict[line]=None # we don't care about the value

Of course here again you'd better create numbers of sub-dictionaries (for example as i showed just before for the lists)

jice 53 Posting Whiz in Training

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)

alreadyStored=[]
for line in file(filename):
    if not (line in alreadyStored): # You may use part of the line, depending on the key you want to use
        generateSqlInsert() # You know how to do this
        alreadyStored.append(line)

Of course, it is better to define more than one list but I think than testing presence in the list is faster than sorting (I didn't test so maybe am I wrong)

By the way, to increase readability, instead of writing

'insert into database.table values (scn_telco.npanxx_id_seq.nextval,0,\
\'%s\',\'%s\',%s,%s,\'%s\',\'%s\',\'%s\',\'X\',\'%s\',%s,\'\');\n'

You can use "

"insert into database.table values (scn_telco.npanxx_id_seq.nextval,0,\
'%s','%s',%s,%s,'%s','%s','%s','X','%s',%s,'');\n"

Looks better no ?

jice 53 Posting Whiz in Training


I know, its ugly :) I'm no programmer. It's complaining about line 26, which is:
if fnmatch.fnmatch(filename, '*.vob'):

And what does he say (Which exception is thrown) ?

jice 53 Posting Whiz in Training

but how can i prove for example that the result of sqrt(n) is an integer?

You can do this (maybe is there more elegant way)

if math.sqrt(n) == float(int(math.sqrt(n))):
    print "sqrt(n) is an integer"
vegaseat commented: nice work +7
jice 53 Posting Whiz in Training

You should look at Tkinter (available in the normal python distrib) - It would be much simpler than reinvent the wheel.
http://www.ferg.org/thinking_in_tkinter/index.html

jice 53 Posting Whiz in Training

Well, maybe... I don't think this may be a problem. it's just like when you have to be careful about {{{ and }}}.
The positive point of that is that you HAVE to be careful of your code readability.
Python is compact and clear (and that's why I use it instead of perl for instance)

jice 53 Posting Whiz in Training

Hi,
In python, blocks structure rely on indentation

while E:
    Bt
else:
    Bf
back to the while level