Re: [Tutor] delphi, pascal and Python

2009-05-21 Thread Alan Gauld


"Marc Tompkins"  wrote

 Is there a Method for wrapping delphi and/or pascal code into python 
like

SWIG?

http://membres.lycos.fr/marat/delphi/python.htm


That's a package to let you embed Python in Delphi; the OP wants to go 
the

other direction.


So it is, I didn't read the OP question closely enough.

On Windows you could create a DLL and use ctypes to access it,
but thats not the same as creating an importable module as could
be done with SWIG

Alan G. 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting file properties on winodws

2009-05-21 Thread vishwajeet singh
Hi Tim,

It does not seems to be working for jpg and in general with image files any
pointers on that.

Thanks for your help.

On Thu, May 21, 2009 at 2:40 AM, vishwajeet singh wrote:

> Thanks that helped.
>
>
> On Thu, May 21, 2009 at 2:34 AM, Tim Golden  wrote:
>
>> vishwajeet singh wrote:
>>
>>> Hi,
>>>
>>> I am trying to read properties of file on windows like there is a
>>> property
>>> call Keywords on file; I am to read this property independent of file
>>> type.
>>>
>>
>> There's an unpolished (indeed, unfinished) example here:
>>
>>
>> http://timgolden.me.uk/python/win32_how_do_i/get-document-summary-info.html
>>
>> TJG
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Cheers,
> Vishwajeet
> http://www.singhvishwajeet.com
>



-- 
Cheers,
Vishwajeet
http://www.singhvishwajeet.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hi everyone

2009-05-21 Thread spir
Le Wed, 20 May 2009 18:25:07 -0700 (PDT),
Doug Reid  s'exprima ainsi:

> "The next line in the loop,
>word = word[:position] + word[(position + 1):]
> 
> creates a new version of word minus the one letter at position position.
> Using slicing, the computer creates two new strings from word. The first
> slice, word[:position], is every letter up to, but not including,
> word[position]. The next slice, word[(position + 1):], is every letter
> after word[position]. These two string are joined together and assigned to
> word, which is now equal to its old self, minus the one letter
> word[position]."

>Can someone explain this in simpler terms? I'm sorry this
> is so lengthy for my first post:) 

It's confusing because abstract and without any example. In the case you wrote 
where the word is "python", the letter 'y', and so the position is 1, you get:
word"python"
word[:position] "p"
word[position+1:]   "thon"
glued together  "pthon"
Also, a confusing part of the program id the loop header:

while word:
    position = random.randrange(len(word))
    jumble += word[position]
    word = word[:position] + word[(position + 1):]

In python, a container such as a string is considered 'False' when it's empty. 
Right? So that the loop header above is equivalent to:
while len(word) > 0:
and the loop will stop when every letter has been extracted from the word.

Denis
--
la vita e estrany
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting file properties on winodws

2009-05-21 Thread Tim Golden

[Rearranging for reading order]

[vishwajeet singh wrote]
I am trying to read properties of file on windows like there is a
property
call Keywords on file; I am to read this property independent of file
type.

[Tim Golden  wrote:]
There's an unpolished (indeed, unfinished) example here:
http://timgolden.me.uk/python/win32_how_do_i/get-document-summary-info.html

[vishwajeet singh wrote:]

It does not seems to be working for jpg and in general with image files any
pointers on that.


It would probably help if you specified what "does not seem[s] to be
working" meant. But I assume that you mean: if you add a Title into
the Summary on a JPEG then it doesn't get picked up by the script.
What's happening here (I think) is that for media types -- images,
movies, etc. -- the [Summary] property sheet is overridden, probably
by Windows Media Player which will use the properties embedded in
the JPEG (EXIF) or WMV. This isn't Structured Storage as such and
so isn't extracted by the script I showed.

If I get a chance, I'll look into this a bit further.

TJG
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting file properties on winodws

2009-05-21 Thread vishwajeet singh
Hi Tim,

My apologies for being vague. Yes you are right I am not able to get any
summary property from a image file.
Script runs successfully without printing anything.

Thanks for your help.


On Thu, May 21, 2009 at 1:43 PM, Tim Golden  wrote:

> [Rearranging for reading order]
>
> [vishwajeet singh wrote]
> I am trying to read properties of file on windows like there is a
> property
> call Keywords on file; I am to read this property independent of file
> type.
>
> [Tim Golden  wrote:]
> There's an unpolished (indeed, unfinished) example here:
> http://timgolden.me.uk/python/win32_how_do_i/get-document-summary-info.html
>
> [vishwajeet singh wrote:]
>
>> It does not seems to be working for jpg and in general with image files
>> any
>> pointers on that.
>>
>
> It would probably help if you specified what "does not seem[s] to be
> working" meant. But I assume that you mean: if you add a Title into
> the Summary on a JPEG then it doesn't get picked up by the script.
> What's happening here (I think) is that for media types -- images,
> movies, etc. -- the [Summary] property sheet is overridden, probably
> by Windows Media Player which will use the properties embedded in
> the JPEG (EXIF) or WMV. This isn't Structured Storage as such and
> so isn't extracted by the script I showed.
>
> If I get a chance, I'll look into this a bit further.
>
>
> TJG
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Cheers,
Vishwajeet
http://www.singhvishwajeet.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting file properties on winodws

2009-05-21 Thread Kent Johnson
On Thu, May 21, 2009 at 4:25 AM, vishwajeet singh  wrote:
> Hi Tim,
>
> My apologies for being vague. Yes you are right I am not able to get any
> summary property from a image file.
> Script runs successfully without printing anything.

If  you are specifically looking to read EXIF tags from jpg files then
try exif.py:
http://exif-py.sourceforge.net/

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



Re: [Tutor] Hi everyone

2009-05-21 Thread W W
On Thu, May 21, 2009 at 2:42 AM, spir  wrote:

> 
>while word:
> position = random.randrange(len(word))
>jumble += word[position]
>word = word[:position] + word[(position + 1):]
>

Something that many of us use for debugging, and is also useful for
comprehension is a simple print statement. If you were to convert the loop
to this:

while word:
position = random.randrange(len(word))
   jumble += word[position]
   word = word[:position] + word[(position + 1):]
   print jumble
   print word
   # Optional - for further understanding
   print word[:position]
   print word[(position+1):]

you would basically see what Denis wrote - only every step through the loop.

HTH,
Wayne

p.s. - When you start graphical programming, I'd look at pyglet or pygame.
Although to really understand event driven programming, it really helped me
to start writing programs with Tkinter. YMMV
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hi everyone....thanks for the help

2009-05-21 Thread Doug Reid
Thank you all for the help.  I believe I understand now, and think this will be 
a great group to learn from.
 
Doug


  ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting file properties on winodws

2009-05-21 Thread Tim Golden

Tim Golden wrote:

It would probably help if you specified what "does not seem[s] to be
working" meant. But I assume that you mean: if you add a Title into
the Summary on a JPEG then it doesn't get picked up by the script.
What's happening here (I think) is that for media types -- images,
movies, etc. -- the [Summary] property sheet is overridden, probably
by Windows Media Player which will use the properties embedded in
the JPEG (EXIF) or WMV. This isn't Structured Storage as such and
so isn't extracted by the script I showed.

If I get a chance, I'll look into this a bit further.


In principle, it ought to be possible to do this by
querying the IID_IPropertySetStorage on the corresponding
IID_IShellItem. But it doesn't look as though the pywin32
com stuff quite supports that yet. Could be wrong. Might
be worth trying with comtypes; I'll have a look if I can.

TJG
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting file properties on winodws

2009-05-21 Thread Tim Golden

Tim Golden wrote:

Tim Golden wrote:

It would probably help if you specified what "does not seem[s] to be
working" meant. But I assume that you mean: if you add a Title into
the Summary on a JPEG then it doesn't get picked up by the script.
What's happening here (I think) is that for media types -- images,
movies, etc. -- the [Summary] property sheet is overridden, probably
by Windows Media Player which will use the properties embedded in
the JPEG (EXIF) or WMV. This isn't Structured Storage as such and
so isn't extracted by the script I showed.

If I get a chance, I'll look into this a bit further.


In principle, it ought to be possible to do this by
querying the IID_IPropertySetStorage on the corresponding
IID_IShellItem. But it doesn't look as though the pywin32
com stuff quite supports that yet. Could be wrong. Might
be worth trying with comtypes; I'll have a look if I can.


OK, more useful version now up; reads JPEGs, WMVs, etc.
Still more work to be done, reverse-engineering the FMTID
and property names, but at least it takes you further without
too much extra work.

 http://timgolden.me.uk/python/win32_how_do_i/get-document-summary-info.html

TJG
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting file properties on winodws

2009-05-21 Thread vishwajeet singh
On Fri, May 22, 2009 at 1:23 AM, Tim Golden  wrote:

> Tim Golden wrote:
>
>> Tim Golden wrote:
>>
>>> It would probably help if you specified what "does not seem[s] to be
>>> working" meant. But I assume that you mean: if you add a Title into
>>> the Summary on a JPEG then it doesn't get picked up by the script.
>>> What's happening here (I think) is that for media types -- images,
>>> movies, etc. -- the [Summary] property sheet is overridden, probably
>>> by Windows Media Player which will use the properties embedded in
>>> the JPEG (EXIF) or WMV. This isn't Structured Storage as such and
>>> so isn't extracted by the script I showed.
>>>
>>> If I get a chance, I'll look into this a bit further.
>>>
>>
>> In principle, it ought to be possible to do this by
>> querying the IID_IPropertySetStorage on the corresponding
>> IID_IShellItem. But it doesn't look as though the pywin32
>> com stuff quite supports that yet. Could be wrong. Might
>> be worth trying with comtypes; I'll have a look if I can.
>>
>
> OK, more useful version now up; reads JPEGs, WMVs, etc.
> Still more work to be done, reverse-engineering the FMTID
> and property names, but at least it takes you further without
> too much extra work.
>
>
> http://timgolden.me.uk/python/win32_how_do_i/get-document-summary-info.html
>
> TJG
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

Hi Tim,

Thanks for your help; I am able to get required properties from jpg files.

-- 
Cheers,
Vishwajeet
http://www.singhvishwajeet.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Parsing Bible verses

2009-05-21 Thread Eduardo Vieira
Hello, I'm planning to create a script to read a certain file, find
the line that contains Bible references and then use that to query a
bible database in order to print the verses in another file.
I will be looking for lines like these:
Lesson Text: Acts 5:15-20, 25; 10:12; John 3:16; Psalm 23

So, references in different chapters are separated by a semicolon. My
main challenge would be make the program guess that 10:12 refers to
the previous book. 15-20 means verses 15 thru 20 inclusive. I'm afraid
that will take more than Regex and I never studied anything about
parser tools, really.

Any suggestion how I should approach this?

Eduardo
www.expresssignproducts.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing Bible verses

2009-05-21 Thread W W
On Thu, May 21, 2009 at 4:26 PM, Eduardo Vieira wrote:

> Hello, I'm planning to create a script to read a certain file, find
> the line that contains Bible references and then use that to query a
> bible database in order to print the verses in another file.
> I will be looking for lines like these:
> Lesson Text: Acts 5:15-20, 25; 10:12; John 3:16; Psalm 23
>
> So, references in different chapters are separated by a semicolon. My
> main challenge would be make the program guess that 10:12 refers to
> the previous book. 15-20 means verses 15 thru 20 inclusive. I'm afraid
> that will take more than Regex and I never studied anything about
> parser tools, really.
>
> Any suggestion how I should approach this?
>

Actually, a regex probably wouldn't be too far off. If you're comfortable
working with them it may even be a good thing...
Will the line always begin with "Lesson text:"? If so, that makes it a lot
easier. Something like:

for line in file:
if line starts with "Lesson text":
skip "lesson text"
book = first word(s)
verse[book] = list of references

that's a really basic flow of logic, but it's probably how I'd do it.

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing Bible verses

2009-05-21 Thread John Fouhy
2009/5/22 Eduardo Vieira :
> I will be looking for lines like these:
> Lesson Text: Acts 5:15-20, 25; 10:12; John 3:16; Psalm 23
>
> So, references in different chapters are separated by a semicolon. My
> main challenge would be make the program guess that 10:12 refers to
> the previous book. 15-20 means verses 15 thru 20 inclusive. I'm afraid
> that will take more than Regex and I never studied anything about
> parser tools, really.

Well, pyparsing is one of the standard python parsing modules.  It's
not that bad, really :-)

Here's some code I knocked out:

from pyparsing import *

SingleVerse = Word(nums)
VerseRange = SingleVerse + '-' + SingleVerse
Verse = VerseRange | SingleVerse
Verse = Verse.setResultsName('Verse').setName('Verse')
Verses = Verse + ZeroOrMore(Suppress(',') + Verse)
Verses = Verses.setResultsName('Verses').setName('Verses')

ChapterNum = Word(nums)
ChapterNum = ChapterNum.setResultsName('Chapter').setName('Chapter')
ChapVerses = ChapterNum + ':' + Verses
SingleChapter = Group(ChapVerses | ChapterNum)

Chapters = SingleChapter + ZeroOrMore(Suppress(';') + SingleChapter)
Chapters = Chapters.setResultsName('Chapters').setName('Chapters')

BookName = CaselessLiteral('Acts') | CaselessLiteral('Psalm') |
CaselessLiteral('John')
BookName = BookName.setResultsName('Book').setName('Book')

Book = Group(BookName + Chapters)
Books = Book + ZeroOrMore(Suppress(';') + Book)
Books = Books.setResultsName('Books').setName('Books')

All = CaselessLiteral('Lesson Text:') + Books + LineEnd()

s = 'Lesson Text: Acts 5:15-20, 25; 10:12; John 3:16; Psalm 23'
res = All.parseString(s)

for b in res.Books:
for c in b.Chapters:
if c.Verses:
for v in c.Verses:
print 'Book', b[0], 'Chapter', c[0], 'Verse', v
else:
print 'Book', b[0], 'Chapter', c[0]

##

Hopefully you can get the idea of most of it from looking at the code.

Suppress() means "parse this token, but don't include it in the results".

Group() is necessary for getting access to a list of things -- you can
experiment by taking it out and seeing what you get.

Obviously you'll need to add more names to the BookName element.

Obviously also, there is a bit more work to be done on Verses.  You
might want to look into the concept of "parse actions".  A really
simple parse action might be this:

def convertToNumber(string_, location, tokens):
""" Used in setParseAction to make numeric parsers return numbers. """

return [int(tokens[0])]

SingleVerse.setParseAction(convertToNumber)
ChapterNum.setParseAction(convertToNumber)

That should get you python integers instead of strings.  You can
probably do more with parseActions to, for instance, turn something
like '15-20' into [15,16,17,18,19,20].

HTH!

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing Bible verses

2009-05-21 Thread Eduardo Vieira
On Thu, May 21, 2009 at 7:03 PM, John Fouhy  wrote:
> 2009/5/22 Eduardo Vieira :
>> I will be looking for lines like these:
>> Lesson Text: Acts 5:15-20, 25; 10:12; John 3:16; Psalm 23
>>
>> So, references in different chapters are separated by a semicolon. My
>> main challenge would be make the program guess that 10:12 refers to
>> the previous book. 15-20 means verses 15 thru 20 inclusive. I'm afraid
>> that will take more than Regex and I never studied anything about
>> parser tools, really.
>
> Well, pyparsing is one of the standard python parsing modules.  It's
> not that bad, really :-)
>
> Here's some code I knocked out:
>
> from pyparsing import *
>
> SingleVerse = Word(nums)
> VerseRange = SingleVerse + '-' + SingleVerse
> Verse = VerseRange | SingleVerse
> Verse = Verse.setResultsName('Verse').setName('Verse')
> Verses = Verse + ZeroOrMore(Suppress(',') + Verse)
> Verses = Verses.setResultsName('Verses').setName('Verses')
>
> ChapterNum = Word(nums)
> ChapterNum = ChapterNum.setResultsName('Chapter').setName('Chapter')
> ChapVerses = ChapterNum + ':' + Verses
> SingleChapter = Group(ChapVerses | ChapterNum)
>
> Chapters = SingleChapter + ZeroOrMore(Suppress(';') + SingleChapter)
> Chapters = Chapters.setResultsName('Chapters').setName('Chapters')
>
> BookName = CaselessLiteral('Acts') | CaselessLiteral('Psalm') |
> CaselessLiteral('John')
> BookName = BookName.setResultsName('Book').setName('Book')
>
> Book = Group(BookName + Chapters)
> Books = Book + ZeroOrMore(Suppress(';') + Book)
> Books = Books.setResultsName('Books').setName('Books')
>
> All = CaselessLiteral('Lesson Text:') + Books + LineEnd()
>
> s = 'Lesson Text: Acts 5:15-20, 25; 10:12; John 3:16; Psalm 23'
> res = All.parseString(s)
>
> for b in res.Books:
>    for c in b.Chapters:
>        if c.Verses:
>            for v in c.Verses:
>                print 'Book', b[0], 'Chapter', c[0], 'Verse', v
>        else:
>            print 'Book', b[0], 'Chapter', c[0]
>
> ##
>
> Hopefully you can get the idea of most of it from looking at the code.
>
> Suppress() means "parse this token, but don't include it in the results".
>
> Group() is necessary for getting access to a list of things -- you can
> experiment by taking it out and seeing what you get.
>
> Obviously you'll need to add more names to the BookName element.
>
> Obviously also, there is a bit more work to be done on Verses.  You
> might want to look into the concept of "parse actions".  A really
> simple parse action might be this:
>
> def convertToNumber(string_, location, tokens):
>    """ Used in setParseAction to make numeric parsers return numbers. """
>
>    return [int(tokens[0])]
>
> SingleVerse.setParseAction(convertToNumber)
> ChapterNum.setParseAction(convertToNumber)
>
> That should get you python integers instead of strings.  You can
> probably do more with parseActions to, for instance, turn something
> like '15-20' into [15,16,17,18,19,20].
>
> HTH!
>
> --
> John.
>
Thanks for the thorough example, I guess I really should get into this
thing of parsing somehow.
To W W. I guess that approach can work too. I will study both things
and if I get stumped, I'll try the list again. It will take a while
for me to really delve into the task, but I want to do it for a good
friend of mine.

Eduardo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor