Re: [Tutor] how to convert between type string and token

2005-11-14 Thread Danny Yoo


On Mon, 14 Nov 2005, enas khalil wrote:

> hello all

[program cut]

Hi Enas,

You may want to try talking with NTLK folks about this, as what you're
dealing with is a specialized subject.  Also, have you gone through the
tokenization tutorial in:

http://nltk.sourceforge.net/tutorial/tokenization/nochunks.html#AEN276

and have you tried to compare your program to the ones in the tutorial's
examples?



Let's look at the error message.

>   File "F:\MSC first Chapters\unigramgtag1.py", line 14, in -toplevel-
> for tok in train_tokens: mytagger.train(tok)
>   File "C:\Python24\Lib\site-packages\nltk\tagger\__init__.py", line 324, in 
> train
> assert chktype(1, tagged_token, Token)
>   File "C:\Python24\Lib\site-packages\nltk\chktype.py", line 316, in chktype
> raise TypeError(errstr)
> TypeError:
> Argument 1 to train() must have type: Token
>   (got a str)

This error message implies that each element in your train_tokens list is
a string and not a token.


The 'train_tokens' variable gets its values in the block of code:

###
train_tokens = []
xx=Token(TEXT=open('fataha2.txt').read())
WhitespaceTokenizer().tokenize(xx)
for l in xx:
train_tokens.append(l)
###


Ok.  I see something suspicious here.  The for loop:

##
for l in xx:
train_tokens.append(l)
##

assumes that we get tokens from the 'xx' token.  Is this true?  Are you
sure you don't have to specifically say:

##
for l in xx['SUBTOKENS']:
...
##

The example in the tutorial explicitely does something like this to
iterate across the subtokens of a token.  But what you're doing instead is
to iterate across all the property names of a token, which is almost
certainly not what you want.

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


Re: [Baypiggies] BayPIGgies: December 8, 7:30pm (IronPort)

2005-12-05 Thread Danny Yoo
> Advance notice:  We need speakers for January and later.  Please send
> e-mail to [EMAIL PROTECTED] if you want to suggest an agenda (or
> volunteer to give a presentation).

Correction: that email address should be '[EMAIL PROTECTED]'.

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


Re: [Python-Help] Programming help

2004-12-06 Thread Danny Yoo


On Mon, 6 Dec 2004, Alfred Canoy wrote:

> Please help me out:(.. I've been trying to figure this out for 2 days
> now.. I don't know what to use to print all the list of numbers. I hve
> know idea how should I do this. I tried a lot of trial & error for the
> the def, dict, .list( ). have no luck.


Hi Alfred.

When you are reading numbers from the user, you should be careful to store
those numbers somewhere.  That is, you need to "collect" each new number
in some kind of container.


Take a look at:

http://www.freenetpages.co.uk/hp/alan.gauld/tutdata.htm

The "Collections" section of that page has tutorial material on how to
collect a bunch of numbers in a single container.


Good luck to you!

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


Re: [Tutor] Convert Qstring to string in windows

2014-10-16 Thread Danny Yoo
On Thu, Oct 16, 2014 at 8:21 AM, C@rlos  wrote:
>
> I have been tryed to convert a Qstring text to string on python, in linux
> that work fine but in windows when qstring contine á,é,í,ó,ú the converted
> text is not correct, contine extranger characters,
> this qstring text is an url from qdialogtext.
>
> in linux i do for this way:
> pythonstringtext=qstringtext.text().toUtf8.data()
> and it return a python string correctly.


Hi Carlos,

This seems like a question that's very specific to Qt: you may want to
ask on a Qt-Python mailing list.  Tutor is intended for beginner
programmers, and the question you're asking seems a bit specialized
for the intended audience.


In absence of this information, I have to make a few guesses.  My best
guesses so far are that you're working with Qt, which provides its own
Unicode string class:

http://qt-project.org/doc/qt-4.8/qstring.html

Are you using PyQt 4 or PyQt 5, or something else entirely?  Are you
using Python 2 or Python 3?

According to the PyQt5 documentation, it automatically handles the
string conversion:


http://pyqt.sourceforge.net/Docs/PyQt5/gotchas.html#python-strings-qt-strings-and-unicode

and according to the PyQt 4 documentation, it also handles the
conversion automatically for you:

http://pyqt.sourceforge.net/Docs/PyQt4/python_v3.html#qstring

and because the mapping is done by the library, you should not have to
be doing anything on your own end to convert Qstrings to Python
strings.


Yeah, I am not sure what you are doing yet, because the documentation
says that it handles conversions for you.  The fact that you're doing
this manually suggests that you might be doing something unusual.  We
need more information.  But I think you may get better help on a
Qt-specific mailing list; I suspect very few of us here have Qt
experience.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Help] os listdir access denied when run as a service

2006-05-25 Thread Danny Yoo


On Thu, 25 May 2006, Thomas Thomas wrote:


> I am trying to access a mapped network drive folder. everything works 
> fine normally. But when i run the application as service I am getting 
> the error

The error is on the line:

 for filename in os.listdir(folder):#line 25

and I have to assume that the bad call here is to os.listdir().



What's the particular input that's being sent to os.listdir() at the point 
of failure?  As far as I can tell, the error message:

> Traceback (most recent call last):
>  File "docBoxApp.py", line 129, in ?
>  File "core\PollFiles.pyc", line 332, in doPoll
>  File "core\PollFiles.pyc", line 47, in createFileList
>  File "core\PollFiles.pyc", line 25, in addFolderFiles
> WindowsError: [Errno 5] Access is denied:'G:\\DT Hot Folder test/*.*'

suggests that 'G:\\DT Hot Folder test/*.*' might be the folder being 
passed.  If so, that could be the problem, since os.listdir takes the name 
of a directory: it does not take a file glob.


Can you check to see what 'folder' is being passed into your program in 
the context of a file service?  The problem may simply be bad input.


We can check early on this by programming a bit defensively, mandating 
that on entry to addFolderFiles that 'folder' must be an existing 
directory:


def addFolderFiles(folder, filelist=[]):
 assert os.path.isdir(folder)
 ...


in which case, if we get past the assertion, we'll be able to at least 
know that we're getting in semi-good input.



One other note: it is not recommended that we use a list as a default 
parameter value.  That value will be shared among all calls to 
addFolderFiles, so we will see side effects.  See the "Important Warning" 
in:

http://docs.python.org/tut/node6.html#SECTION00671
-- 
http://mail.python.org/mailman/listinfo/python-list