Repository of non-standard modules.

2013-07-31 Thread Gabor Urban
Hi,

I am to start a new free-time project in the next couple of weeks. I am
ready to use open accessible Python modules not wanting to reinvent the
weel :-)
Is there any repository where I can find Python modules not being part of
the standard distribution?

I have some hits by Google but that seems to be far from complete.

Thanks in advance,

Gabor Urban

-- 
Urbán Gábor

Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
http://mail.python.org/mailman/listinfo/python-list


Testing list sequence question

2023-03-04 Thread Gabor Urban
 Hi guys,

I have a strange problem that I do not understand. I am testing function
which returns a dictionary. The code should ensure that the keys of the
dictionary are generated in a given order.

I am testing the function with the standard unittest module and use the
assertListEqual statement to verify the sequence. Sometimes this test
fails, sometimes passes without any change neither in the code, nor in the
testcase. I am using "list(myDict.keys())" to create the list of the keys
of the dictionary.

I am running Python 3.3 on MS Windows. Any idea why is this?

Thx, Gabor

-- 
Urbán Gábor

Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
https://mail.python.org/mailman/listinfo/python-list


Testing list sequence question -- thanks for the info

2023-03-05 Thread Gabor Urban
Hi guys,

Thank you very much for the accurate answer.

Upgrading our Python to 3.7 seems to be out of question at the moment. I
will check the requirement specification if the order of the keys is
important at all.
It could be a wish only.

-- 
Urbán Gábor

Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
https://mail.python.org/mailman/listinfo/python-list


Module import question

2020-08-08 Thread Gabor Urban
Hi guys,

I have a quite simple question but I could not find the correct answer.

I have twoo modules A and B. A imports B. If I import A in a script, Will
be B imported automatically? I guess not, but fő not know exactly.

Thanks for your answer ín advance,

Gábor
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Module import question

2020-08-09 Thread Gabor Urban
Hi guys,

Thanks for the answers. IT is clear Noé.

Gábor
-- 
https://mail.python.org/mailman/listinfo/python-list


A problem with opening a file

2020-11-28 Thread Gabor Urban
Hi,

I am facing an issue I was not able to solve yet. I have a class saving
messages to a file. The relevant code is:



import OS
import sys

class MxClass:

def __init__(self, fName, fMode,):
self.fileName = fName
self.fileMode = fMode


def writeMethod(self, message):
data = open(self.fileName, self.fileMode)




Tests reveal: the class is instantiated correctly, other methods work
perfect. The writeMethod raises a NameError opening the file
"name 'open' is not defined "

I am stuck here.


-- 
Urbán Gábor

Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
https://mail.python.org/mailman/listinfo/python-list


A problem with opening a file -- again

2020-11-29 Thread Gabor Urban
Hi guys,

I tried to solve the problem once again. I have inserted some print
statements the check the variables.

The actual code (naplo.py) is copy-pasted here:



class Naplo:
def __init__(self, pNeve, pMeret, pMode = 'a'):
self.logNev = pNeve
self.meret = pMeret
self.startMode = pMode
self.mode = 'a'
self.sor = 0
self.puffer = []
self.start = True

def __del__(self):
print(' .. sor = %d'%self.sor)
print(' .. startMode = %s'%self.startMode)
print(' .. mode = %s'%self.mode)
print(' .. logName = %s'%self.logNev)
print(self.puffer)
if self.sor != 0:
if self.start:
trc = open(self.logNev,self.startMode)
else:
trc = open(self.logNev,self.mode)
for idx in xrange(self.meret):
trc.write(self.puffer[idx])
trc.close()


def Kiir(self, txt):
msg = '%s\n'%txt
self.puffer.append(msg)
self.sor += 1
print(' .. sor = %d'%self.sor)
print(' .. startMode = %s'%self.startMode)
print(' .. mode = %s'%self.mode)
print(' .. logName = %s'%self.logNev)
print(self.puffer)
print('.. ' + self.logNev)
if self.sor == self.meret:
if self.start:
trc = open(self.logNev,self.startMode)
else:
trc = open(self.logNev,self.mode)
for idx in xrange(self.meret):
trc.write(self.puffer[idx])
trc.close()
self.start = False
self.puffer = []
self.sor = 0

lf = Naplo('nap1.log', 6)
lf.Kiir('Ez az elso.')

 

I am using a Windows version:

python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit
(AMD64)]
 on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z

 

python naplo.py
 .. sor = 1
 .. startMode = a
 .. mode = a
 .. logName = nap1.log
['Ez az elso.\n']
.. nap1.log
 .. sor = 1
 .. startMode = a
 .. mode = a
 .. logName = nap1.log
['Ez az elso.\n']
Exception ignored in: >
Traceback (most recent call last):
  File "naplo.py", line 20, in __del__
NameError: name 'open' is not defined

-- 
Urbán Gábor

Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 2.3 and ODBC

2014-04-08 Thread Gabor Urban
Hi guys,

I am using Python 2.3 on an XP box at my company. (I know it is quite
outdated, but we could not make the management to upgrade.) I have started
a pilot project the last week to show the possibility of processing
incoming XML files and extracting data into Oracle tables.

Now I am almost ready, but need to use an ODBC module with Python. What do
you suggest?

BTW if my demo will be good, we hope to have an aproval to change to Python
3.3

Thanks in advance


-- 
Urbán Gábor

Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
https://mail.python.org/mailman/listinfo/python-list


Teaching Python

2014-09-29 Thread Gabor Urban
Hi,

my 11 years old son and his classmate told me, that they would like to
learn Python. They did some programming in Logo and turtle graphics, bat
not too much.

Doesn anybody has an idea how to start?

-- 
Urbán Gábor

Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
https://mail.python.org/mailman/listinfo/python-list


Set initial size in TKinter

2011-12-20 Thread Gabor Urban
Hi,

I am quite newbie with Tkinter and I could not find the way to set the
size of the application. (I could find the method to make it
resizeable, though :-)) ) Any ideas, suggestions or links to
references are wellcome.

Here is my code:

from Tkinter import *

class Application(Frame):
def say_hi(self):
self.db += 1
print 'hi there, -->> UG everyone! db = %d'%self.db

## TODO: meretezhetoseg
def createWidgets(self):
  top = self.winfo_toplevel()
  top.rowconfigure(0,weight = 1)
  top.columnconfigure(0,weight = 1)
  self.rowconfigure(0,weight = 1)
  self.columnconfigure(0,weight = 1)
  self.QUIT = Button(self)
  self.QUIT["text"] = "QUIT"
  self.QUIT["fg"]   = "red"
  self.QUIT["command"] =  self.quit

  self.QUIT.pack({"side": "left"})

  self.hi_there = Button(self)
  self.hi_there["text"] = "Hello",
  self.hi_there["command"] = self.say_hi

  self.hi_there.pack({"side": "left"})

def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
self.db = 0

app = Application()
app.master.title('UG test')
app.mainloop()



Thx in advance...

Gabor

-- 
Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs

2007-06-20 Thread Gabor Urban

Hi guys...

This topic is not relevant in this mailing list.

Though some info from an other mailing list. Emacs (and xemacs) runs
perfectly well on non-gui environments as well. So keyboard commands are the
only efficient way to work with. It is true,  Emacs may be a bit antiquated,
but it honed to an edge GUI tools are very far from. It is like a Formule-1
race car. You do not need automatic gears to drive it faster, do you?

Learning Emacs is not easy but you can start with amazingly little
knowledge. Skills come with usage. I know, I started it 10 years ago, well
in the GUI era.

Yes, vim. Very fine and powerfull tool, as good as Emacs. It is a quiestion
of taste. I use both these times
-- 
http://mail.python.org/mailman/listinfo/python-list

Emacs topic

2007-06-21 Thread Gabor Urban

Hi guys,

I kindly ask you to stop this topic. Though I see the importance to have a
good editor for programming, this is outside of the focus of a Python
mailing list.

The open source world offers a lot of very good tools to edit source files,
even for cross-platform development. Emacs is one of them, and IMHO could be
set as an efficiency/proficiency standard. But if it does not fit to your
fingers or working style, do not use it.

I am open to personal debate outside of this list,

Gabor
-- 
http://mail.python.org/mailman/listinfo/python-list

Emacs topic should be stopped....

2007-06-25 Thread Gabor Urban

Hi guys,

I was going through most of this topic, but I find this not relevant on THIS
mailing list...

A short summary: there are some people who are not disturbed by proven
facts. They are mostly attackers of emacs/Xemacs or vim... Or even linux and
open source. Quite funny, since this is a mailing list of an open source
programming language. :-

Arguments and logic are not working, it's been a 'religious' flame topic.

I am open to discuss this issue further in private..

Gabor
-- 
http://mail.python.org/mailman/listinfo/python-list

Dynamic method

2007-07-10 Thread Gabor Urban

Hi guys.

I have an issue I think Python could handle. But I do not have the knowledge
to do it.

Suppose I have a class 'myClass' and instance 'var'. There is function
'myFunc(..)'. I have to add (or bind) somehow the function to the class, or
the instance. Any help, info or point of reference is wellcome

Thx in advance,
G
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The Modernization of Emacs: terminology buffer and

2007-07-13 Thread Gabor Urban

Hullo,

I was just wondering if this thread was whithering out.. I gues not for
a good time.

A short summary in the hope for the last posting in this topic.

Some provocative posting caused or Twister brother to send a large amount of
doubtful info. It seems, he had some very bad experience with an undefined
version of so called 'emacs'. Or he was not able to win against his
prejudice. On the other hand most of the users of the true, standard and
canonical Emacs (and Xemacs as well) were able to point out his factual
errors and misconceptions. (BTW Xemacs is not for X11... just eXtended..
:-)) )

But, for God's sake this is Python list. Would like to stick to it?

Back to Python... which version is to be used in production environment?

Sincerely yours,

gabaux
-- 
http://mail.python.org/mailman/listinfo/python-list

Simple question about logging module.

2007-07-31 Thread Gabor Urban
Hullo,

I have started to use Python's logging, and got a problem. I have created
some loggers and wrote some lines in the log. The problem is, that most of
the lines appear doubled in the log, and some lines do not appear at all.

Any ideas or comments are wellcome,

Gabor

Here is the code:

import sys
import logging

l = logging.getLogger('XmlTester')
handler = logging.StreamHandler(sys.stderr)
l.addHandler(handler)
formatter = logging.Formatter("%(name)s %(asctime)s %(filename)s %(lineno)d
%(levelname)s %(message)s")
handler.setFormatter(formatter)
la = logging.getLogger('XmlTester.XmlParser')
handler = logging.StreamHandler(sys.stderr)
la.addHandler(handler)
handler.setFormatter(formatter)
lb = logging.getLogger('XmlTester.TestExecutor')
handler = logging.StreamHandler(sys.stderr)
lb.addHandler(handler)
handler.setFormatter(formatter)
l.setLevel(logging.DEBUG)
la.setLevel(logging.DEBUG)
lb.setLevel(logging.DEBUG)
l.debug("Start")
la.debug("Start la")
lb.debug("This debug")
lb.info("This started.")
l.info("Info written")
l.warning("This is a warning")
l.error("Error occured")
test = "Info.pck"
la.info("Hi there!")
la.critical("No file named '%s'"%test)
l.critical("End of all")


Here is the output:
XmlTester.XmlParser 2007-07-31 10:34:12,303 plogtest.py 21 DEBUG Start la
XmlTester.XmlParser 2007-07-31 10:34:12,303 plogtest.py 21 DEBUG Start la
XmlTester.TestExecutor 2007-07-31 10:34:12,319 plogtest.py 22 DEBUG This
debug
XmlTester.TestExecutor 2007-07-31 10:34:12,319 plogtest.py 22 DEBUG This
debug
XmlTester.TestExecutor 2007-07-31 10:34:12,319 plogtest.py 23 INFO This
started.
XmlTester.TestExecutor 2007-07-31 10:34:12,319 plogtest.py 23 INFO This
started.
XmlTester.XmlParser 2007-07-31 10:34:12,319 plogtest.py 28 INFO Hi there!
XmlTester.XmlParser 2007-07-31 10:34:12,319 plogtest.py 28 INFO Hi there!
XmlTester.XmlParser 2007-07-31 10:34:12,319 plogtest.py 29 CRITICAL No file
named 'Info.pck'
XmlTester.XmlParser 2007-07-31 10:34:12,319 plogtest.py 29 CRITICAL No file
named 'Info.pck'
XmlTester 2007-07-31 10:34:12,319 plogtest.py 30 CRITICAL End of all
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Simple question about logging module.

2007-07-31 Thread Gabor Urban
Thx guys

You gave me good ideas. At the moment I do not have time for it, but I would
like to write a summary.

Have fun
-- 
http://mail.python.org/mailman/listinfo/python-list

Volume id

2007-11-15 Thread Gabor Urban
Hi,

I have a problem, which may be trivial, but I could not find an answer.

I have to write a Python script, which does a directory tree walking on
given mounted disk. But I do need to extract the volume id, somehow. And
that's the problem.  An additional issue, the script will be used on unix
type systems, and on MS XP or Vista, too

Any ideas are wellcome.

Gabor
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Volume id

2007-11-15 Thread Gabor Urban
OK, you are right... Problem was not precise enough. I need to process CDs
to create a list. Does it ring a bell for you?

Thanks


2007/11/15, Laszlo Nagy <[EMAIL PROTECTED]>:
>
> Gabor Urban wrote:
> > Hi,
> >
> > I have a problem, which may be trivial, but I could not find an answer.
> >
> > I have to write a Python script, which does a directory tree walking
> > on given mounted disk. But I do need to extract the volume id,
> > somehow. And that's the problem.  An additional issue, the script will
> > be used on unix type systems, and on MS XP or Vista, too
> >
> > Any ideas are wellcome.
> I believe (although not 100% sure) that "volume id" always belongs to a
> FAT partition (maybe an NTFS partition?). When you format a partition,
> it will give you a - hopefully unique - volume identifier. I don't think
> that unix partitions (like reiserfs, ext2, ext3, ufs2 etc.) has that
> identifier. I may be wrong, others will probably correct me.
>
> Do you want to know the identifier (serial number?) of the disk device
> instead? E.g. not the partition but the hard disk?
>
> Can you list the platforms/operating systems where you want to use your
> program? It might help to look at the documentation/source code or the
> various hardware diagnostic utilities.
>
> Best,
>
>Laszlo
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Porting to new Python version

2009-02-19 Thread Gabor Urban
Hi,

I have a tough issue: we are using a Python application written quite
a time ago for version 2.4. The code is mature, and there are no bugs.
 My bosses came up with the idea to port it to the latest release... I
am not really convinced that it's a good step.

I wellcome any information pro and contra. I would like to get the
background as precisely as possible.

Thanks in advance and good day to You!

Gabor
--
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, can i ask for a little help? (Andrew Chung)

2009-05-15 Thread Gabor Urban
I gues, it was rather simple...

Begin with simple tasks, figure out how to do them. If you are
proceding well, then increase difficulty/complexity.

Gabor
-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Seeking old post on developers who like IDEs vs developers who like simple languages

2009-05-18 Thread Gabor Urban
Hi guys,

I think this issue is long-long displute over tools and IDE-s. No need
to combine it with the question of the complexity of the programming
language used.

I know guys, who did every development project using a simple GVIM and
command line tools, and vere extremly productive. Even in Java, C++,
and any other languages. For myself I can say, I am a seasoned Emacs
user, and would not switch to any fancy IDE. BUT that is personal
view.

IMHO this question does not bellong here, though I was very pleased to
read arguments instead of flames :-))

Gabor
-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-28 Thread Gabor Urban
I use Emacs, as for the other editing activities. I like it for it is
very powerfull.

-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-28 Thread Gabor Urban
Hi guys,

I would like to reflect this issue for the last time, though I found
this thread to be quite inspiring.

In one the last postings about this topic Steven D'Aprano has written:
"As a general rule, menus are discoverable, while
keyboard commands aren't. There's nothing inherent to text editing
functions which makes then inherently undiscoverable,
and KDE apps like kate and kwrite do a reasonable job of making them so."

I agree with this assumption if, and only if we are speaking about
outsider users.

This is a Python mailing list, which supposed to be a forum of people
using the Python programming language. So Python
source is a plain text, so Python interpreter should be a
command-driven application. With no other UI than the plain old
Command Line Intreface.

MOre than that, all we are supposed to be techmen, who does
acknowledge and appreciate the conceot of wrtitten User Manual or
Reference. All we have learned Python from tutorials and not from the menues.

As a summary, any open source editor should be perfect, which is
extensible, optionally language-sensitive, portable, basically
independent of any OS features. THat cuts the list drammatically.

Gabor
-- 
http://mail.python.org/mailman/listinfo/python-list


Two questions ( Oracle and modules )

2009-12-07 Thread Gabor Urban
Hi guys,

I have two questions.

1. I have choice to introduce Python to my new employee. We are to
write and application that uses databases stored partially in Oracle
10 and partially in Oracle 11. We have to execute standard SQL
commands and stored procedures as well. Which is best conection /
module to use. A couple of years ago we had DCOracle2 for the same
task, but is written for Oracle8, so I gues it might not be a good
idea to use. What is your oppinion?

2. We have tp write a module that will be imported a couple of places.
Though we must be sure, this module's initialization is performed only
once. How can we implement this? I do not know what to google for.

Gabor

-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best vi / emacs python features

2009-10-12 Thread Gabor Urban
Hey guys,

this is supposed to be a Python mailing list...

Both editors are great and are with great potentials. I do use both of
them daily, though for different purposes. It is meaningless to start
this old issue of preferences anew.

-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


Question on PEP 337

2009-10-28 Thread Gabor Urban
Hy guys,

this PEP is very well written, and I have found the discussion inspiring.

Every time I use the logging module, I have the configuration hardcoded in
the application. That is why I never used the configuration file based
approach. Now I will give it a try.

I think we should discuss the following scenario (it was not clear in the
PEP for me) : an application has the logging configuration in a config file
and it is  currently running. The user edits this file, so the configuiration
in the running process should be changed.
-- How will be the logging mechanism reconfigured?
-- How can the logging module guarantee that there will be no data loss
   during the reconfiguration process?


Regards,
Gabor


-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question on PEP 337 (Vinay Sajip)

2009-10-28 Thread Gabor Urban
Hy guys,

Sorry, Vinay Sajip was right. I wrote my questions about PEP 391. I
would like to know your ideas about my questions posted in my last
mail.

Gabor
-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


More Python versions on an XP machine

2009-11-14 Thread Gabor Urban
Hi guys,

this a very MS specific question. I do use a rather old Python
version, because we have a couple of applications written for that.
Porting them to a newer Python is not allowed by the bosses. Now we
will start a new project with latest stable Python. Can I have them
both on my computer, and how should I do that.

Thanks,

PS: This is my computer at the office :-)
-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


Class attributes / methods lost?

2010-03-01 Thread Gabor Urban
Hi guys,

I am building a nested data structure with the following compontens:

<>

class Item:
def __init__(self, pId, pChange, pComment):
self.ID = pId
self.Delta = pChange
self.Comment = pComment

def PrintItem(self):
str = '%s,%s,%s'%(self.ID,self.Delta,self.comment)
return str

class Package:
def __init__(self, pSerial, pDate, pOwner, pSchema):
self.serial = pSerial
self.date = pDate
self.owner = pOwner
self.schema = pSchema
self.items = []

def insertItem(self, pItem):
self.items.append(pItem)

def printPackage(self):
lines = []
str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema)
number = self.items.length
for idx in xrange(number):
line = ''
istr = self.items[idx].PrintItem()
line = str + ',' + istr
lines.append(line)
return lines

<>

The above structure is processed with next code:

<>

size = len(packages)
package = None
for index in xrange(size):
logger.info('PrettyPrinting package id=%d',index)
oplines = []
oplines = packages[index].printPackage()
for i in xrange(oplines.length):
data.append(oplines[i])
<>

I've got the next error message:
' Traceback (most recent call last):
  File "XmlHistory_orig.py", line 203, in ?
oplines = packages[index].printPackage()
TypeError: unbound method printPackage() must be called with Package
instance as first argument (got nothing instead) '

I did give a try to access the fields directly

<>
packages = []
data = []

size = len(packages)
for index in xrange(size):
str = 
'%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema)
itemnum = len(packages[index].items)
oplines = []
for itemIndx in xrange(itemnum):
element =
'%s,%s,%s'%(packages[index].items[itemIdx].ID,packages[index].items[itemIdx].Delta,packages[index].items[itemIdx].comment)
oplines.append(str + ','+elemt)

<>

Error:

Traceback (most recent call last):
  File "XmlHistory.py", line 204, in ?
str = 
'%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema)
AttributeError: class Package has no attribute 'serial'

The strange in this issue for me, that I do not see why are the class
methods and fields lost.

Any idea is wellcome.

Gabor
-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


Class attributes / methods..... full Python script

2010-03-01 Thread Gabor Urban
Hi guys,

thanks for the ideas. Here you are the code. Not transcoded from Java
for I do not know Java enough..

I am scanning an XML file, and have a large ammount of logging.

Any ideas are wellcome as before

Thnx

Code:>

#-
## Generate CSV from OEP History XML
#-

import sys
import os
from xml.dom.minidom import parse, parseString
import xml.dom
import logging

versionStr = '0.01'

class Item:
def __init__(self, pId, pChange, pComment):
self.ID = pId
self.Delta = pChange
self.Comment = pComment

def PrintItem(self):
str = '%s,%s,%s'%(self.ID,self.Delta,self.comment)
return str

class Package:
def __init__(self, pSerial, pDate, pOwner, pSchema):
self.serial = pSerial
self.date = pDate
self.owner = pOwner
self.schema = pSchema
self.items = []

def insertItem(self, pItem):
self.items.append(pItem)

def printPackage(self):
lines = []
str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema)
number = self.items.length
for idx in xrange(number):
line = ''
istr = self.items[idx].PrintItem()
line = str + ',' + istr
lines.append(line)
return lines

def getItem(tracer, pkgItem, itemName):
retval = -1
name = ""
found = 0
str = ""
tracer.info('Function getItem entry, name = %s',itemName)
nItem = pkgItem.getElementsByTagName(itemName).item(0)
for node in pkgItem.childNodes:
if node.nodeType != xml.dom.Node.TEXT_NODE:
tracer.debug('Scanning node name = %s',node.nodeName)
if node.nodeName == itemName:
tracer.debug('Pkg %s found',itemName)
else:
tracer.warning('Pkg %s is not found',itemName)
continue
for entity in node.childNodes:
if entity.nodeType == xml.dom.Node.TEXT_NODE:
retval = entity.nodeValue
tracer.debug("Node value found %s",retval)
found = 1
break
if found == 1:
break
tracer.debug('Function getItem returns %s',retval)
return retval

logger = logging.getLogger('XmlHistory')
handler = logging.FileHandler("Xmlhistory.trc",'a')
## handler = logging.StreamHandler(sys.stderr)
logger.addHandler(handler)
formatter = logging.Formatter("%(name)s %(asctime)s %(filename)s
%(lineno)d %(levelname)s %(message)s")
handler.setFormatter(formatter)
logger.setLevel(2)

fileName = "history.xml"
output = 'history.csv'
logger.info('Xml history generator version %s',versionStr)
logger.info('Starting history generation on file:%s',fileName)

packages = []
data = []

## Start XML processing

dataSource = parse(fileName)
print dataSource.documentElement.tagName
listCsomag = dataSource.getElementsByTagName("csomag")
size = listCsomag.length
logger.debug('Number of packages = %d',size)
for idx in xrange(size):
attrib = ""
package = None
serial = 0
date = ""
owner = ""
schema = ""
flag = False
logger.info('Parsing package id=%d',idx)
attrib = getItem(logger, listCsomag.item(idx),'sorszam')
if attrib <> "NUM" and attrib <> -1:
serial = int(attrib)
flag = True
logger.debug('Package serial set to %d',serial)
else:
logger.debug("Template package found.")
break
attrib = ""
attrib = getItem(logger,listCsomag.item(idx),"datum")
if attrib <> -1:
date = attrib
flag = flag and True
logger.debug('Package date set to %s',date)
attrib = ""
attrib = getItem(logger,listCsomag.item(idx),"ki")
if attrib <> -1:
owner = attrib
flag = flag and True
logger.debug('Package owner set to %s',owner)
attrib = ""
attrib = getItem(logger,listCsomag.item(idx),"sema")
if attrib <> -1:
schema = attrib
flag = flag and True
logger.debug('Package schema set to %s',schema)

if flag <> True:
logger.error('Package id=%d is inconsistent',idx)
break
else:
logger.info('Package id=%d is ok',idx)

package = Package(serial,date,owner,schema)

listItem = listCsomag.item(idx).getElementsByTagName("item")
itemSize = listItem.length
logger.debug('Number of items = %d',itemSize)
for num in xrange(itemSize):
flag = False
value = -1
listId = 0
change = ""
comment = ""
item = None
logger.info('Parsing item id = %d',num)
value = getItem(logger,listItem.item(num),"item_id")
if value <> -1:
listId = int(value)
flag = True
logger.debug('List id set to %d',listId)
value = ""
value = getItem(logger,listItem.item(num),"valtozas")
if value <> -1:
change = value
 

Logging question

2009-09-22 Thread Gabor Urban
Hi guys,

I have embarassing problem using the logging module. I would like to
encapsulate the creation and setting up  of the logger in a class, but
it does not seem working.

Here are my relevant parts of the code:

--
import sys
import logging

class LogClass:
def __init__(self, fileName, loggerName = 'classLog'):
self.Logger = logging.getLogger(loggerName)
self.traceName = fileName
handler = logging.FileHandler(self.traceName,'a')
formatter = logging.Formatter("%(name)s %(asctime)s
%(filename)s %(lineno)d %(levelname)s %(message)s")
handler.setFormatter(formatter)
self.Logger.addHandler(handler)
self.Handler = handler

def closeLog(self):
self.Handler.flush()
self.Handler.close()

def fetchLogger(self):
return self.Logger

if __name__ == "__main__":
name = 'testlog.trc'
classLog = LogClass(name)
logger = classLog.fetchLogger()
logger.info("Created")
logger.debug("Test")
logger.info("Created .. ")
logger.debug("Test data")
classLog.closeLog()

--

The trace file is created properly but contains no lines at all. If I
put the code directly in __main__, it works fine.

What did I miss? Any ideas are wellcome.

Gabor
-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


A question about import

2024-02-16 Thread Gabor Urban via Python-list
Hi guys,

I need something about modules to be clarified.

Suppose I have written a module eg: ModuleA which imports an other
module, let us say the datetime.

If I import ModuleA in a script, will be datetime imported automatically?

Thanks in advance,

--
Urbán Gábor

Linux is like a wigwam: no Gates, no Windows and an Apache inside.
-- 
https://mail.python.org/mailman/listinfo/python-list