Prabhakar K | 1 Mar 08:05 2006
Picon

Fwd: Problem wxPython

Hai to all,
 
        I installed ActivePython-2.4.1-247-win32-ix86 and wxPython2.6-win32-ansi-2.6.2.1-py2 in my system. When i Run a wxPython example.. geeting an Errors
 
Traceback (most recent call last):
  File "E:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "F:\python\wx.py", line 1, in ?
    from wxPython.wx import *
  File "E:\Python24\lib\site-packages\wx-2.6-msw-ansi\wxPython\__init__.py", line 10, in ?
    import _wx
  File "E:\Python24\lib\site-packages\wx-2.6-msw-ansi\wxPython\_wx.py ", line 3, in ?
    from _core import *
  File "E:\Python24\lib\site-packages\wx-2.6-msw-ansi\wxPython\_core.py", line 15, in ?
    import wx._core
  File "F:\python\wx.py", line 1, in ?
    from wxPython.wx import *
ImportError: No module named wx
 
 
Program Code:
 

from wxPython.wx import *

class MyApp(wxApp):
    def OnInit(self):
        frame = wxFrame(NULL, -1, "Hello from wxPython")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app = MyApp(0)
app.MainLoop()

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Andre Engels | 1 Mar 11:58 2006
Picon

password protection in httplib

I am active in pywikipediabot, which is programmed in Python and is
used to edit wikis (based on MediaWiki, such as Wikpedia). It uses
httplib to connect to the site and get the HTML data.

I now want to use it on another site, but this site is password
protected (we want to first improve it before releasing it to the
public). Is it possible with httplib to connect to password protected
sites (given that I know the login and password of course), and if so,
how is this done? If not, is there an alternative?

--
Andre Engels, andreengels <at> gmail.com
ICQ: 6260644  --  Skype: a_engels
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Kent Johnson | 1 Mar 13:05 2006
Picon

Re: password protection in httplib

Andre Engels wrote:
> I am active in pywikipediabot, which is programmed in Python and is
> used to edit wikis (based on MediaWiki, such as Wikpedia). It uses
> httplib to connect to the site and get the HTML data.
> 
> I now want to use it on another site, but this site is password
> protected (we want to first improve it before releasing it to the
> public). Is it possible with httplib to connect to password protected
> sites (given that I know the login and password of course), and if so,
> how is this done? If not, is there an alternative?

What kind of authentication is used? Basic and digest authentication 
will pop up a dialog in the browser asking for your credentials. The 
browser then remembers the credentials and includes them in subsequent 
requests. With form-based authentication, a page displays in the browser 
with a login form; the web site authenticates and usually sends a cookie 
to the browser which must be included in subsequent requests.

urllib2 has good built-in support for basic and digest authentication of 
web sites. For form-based authentication you have to do a bit more work 
  - install a cookie manager and post to the form yourself.

See http://www.voidspace.org.uk/python/articles/authentication.shtml for 
examples of basic auth. Digest auth works pretty much the same way. Make 
sure you read to the section "Doing It Properly" - the author likes to 
show you the hard way first.

The article http://www.voidspace.org.uk/python/articles/cookielib.shtml 
shows how to use cookies, though again the presentation makes it look 
harder than it really is, at least in Python 2.4 that has CookieLib 
built in. You have to post to the login form yourself, but that is just 
another urllib2 request.

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Joaquin Sanchez Sanchez | 1 Mar 17:13 2006
Picon
Picon

URGENT doubt!!!!

I have a doubt
 
I have some modules in python, and in one of them, i have to dictionarys. In them, i have some vars yhat I want to save before clossing my session, ande then, in a new session, i want to load them.
 
I have heard about "pickle"
How does it work?I dont understand the help page example
How have I to used it?
Another suggestion?
 
THANKS A LOT


LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Python | 1 Mar 17:29 2006

Re: URGENT doubt!!!!

On Wed, 2006-03-01 at 17:13 +0100, Joaquin Sanchez Sanchez wrote:
> I have a doubt
>  
> I have some modules in python, and in one of them, i have to
> dictionarys. In them, i have some vars yhat I want to save before
> clossing my session, ande then, in a new session, i want to load them.
>  
> I have heard about "pickle"
> How does it work?I dont understand the help page example
> How have I to used it?
> Another suggestion?

I think the shelve module better fits what you are trying to do.  It
will store the pickle into a file for later retrieval and possible
modification.

http://docs.python.org/lib/module-shelve.html

Note that you should be using strings for the shelve keys.

>  
> THANKS A LOT
> 
> 
> ______________________________________________________________________
> 
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y móviles desde 1 céntimo por minuto.
> http://es.voice.yahoo.com
> _______________________________________________
> Tutor maillist  -  Tutor <at> python.org
> http://mail.python.org/mailman/listinfo/tutor
--

-- 
Lloyd Kvam
Venix Corp

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Kent Johnson | 1 Mar 17:37 2006
Picon

Re: URGENT doubt!!!!

Joaquin Sanchez Sanchez wrote:
> I have a doubt
>  
> I have some modules in python, and in one of them, i have to 
> dictionarys. In them, i have some vars yhat I want to save before 
> clossing my session, ande then, in a new session, i want to load them.
>  
> I have heard about "pickle"
> How does it work?I dont understand the help page example

Yeah, that is an advanced example, for a simple example look at example 
2 on this page:
http://www-128.ibm.com/developerworks/library/l-pypers.html

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Hugo González Monteverde | 1 Mar 18:08 2006
Picon

Re: URGENT doubt!!!!

Ok, if it's so urgent.

import cPickle

mydict = {1:"one", 2:"two"}

#Saving
fileo = open("mysavedfile", "w")
cPickle.dump(mydict, fileo)
fileo.close()

fileo2 = open("mysavedfile", "r")
saved_dict = cPickle.load(fileo2)
print saved_dict

Hope this one is simple enough

Hugo
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Danny Yoo | 1 Mar 19:11 2006
Picon

DOUBT -Its urgent!!!! (fwd)


---------- Forwarded message ----------
Date: Wed, 1 Mar 2006 17:12:47 +0100 (CET)
From: Joaquin Sanchez Sanchez <joaquin_barcelo_12 <at> yahoo.es>
To: tutor-owner <at> python.org
Subject: DOUBT -Its urgent!!!!

I have a doubt

  I have some modules in python, and in one of them, i have to dictionarys. In them, i have some vars yhat I want to
save before clossing my session, ande then, in a new session, i want to load them.

  I have heard about "pickle"
  How does it work?I dont understand the help page example
  How have I to used it?
  Another suggestion?

  THANKS A LOT

---------------------------------

LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y mviles desde 1 cntimo por minuto.
http://es.voice.yahoo.com

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Max Russell | 1 Mar 12:32 2006

Non type object?

I'm trying to debug a script that takes a load of Python files and  checks them against original text files- it's for checking headers:

#script to verify content of a header is what is should be.

import difflib, os, re, sys

class HeaderChecker(object):
    def __init__(self, directoryPy, directoryTxt, outputFilePath=None):
        """script that reverts the headers from a set of Python files
        and checks them against the original text from a test"""
       
        self._directoryToCheck = directoryPy
        self._directoryForCompare =directoryTxt
        self._outputFileName = outputFilePath
       
        # open file to create/clear it
        if self._outputFileName != None:
            outputFile = open(self._outputFileName, "w")
            outputFile.write("Log file for verifying headers")
            outputFile.close()
                          
       
        # get the contents of the Python directory
        if not os.path.exists(self._directoryToCheck):
            raise ScriptException("Directory %s does not exist"%self._directoryToCheck)
                   
        fileList = os.listdir(self._directoryToCheck)
       
        # just look at the python files (make entries with an absolute file path)
        self._pythonFileList = []
        for file in fileList:  
            if file.endswith(".py"):
                self._pythonFileList.append(self._directoryToCheck + "\\" + file)          
               
        print self._pythonFileList
                                           
        if len(self._pythonFileList) == 0:
            raise ScriptException("Directory %s does not contain any python files "%directoryPy)   
               

        #get the contents of the original text directory for comparison
        if not os.path.exists(self._directoryForCompare):
            raise ScriptException("Directory %s does not exist"%self._directoryForCompare)
       
        txtList = os.listdir(self._directoryForCompare)
       
        self._txtFileList = []
        for item in txtList:
            if item.endswith(".txt"):
                self._txtFileList.append(self._directoryForCompare + "\\" + item)
               
        print self._txtFileList
               
        if len(self._txtFileList)==0:
            raise ScriptException("Directory %s does not contain any python files "%directoryTxt)
       
    def getValidPythonFiles(self):
        """
        get valid python files
        """
        self.log(["found %d python files in %s"%(len(self._pythonFileList), self._directoryToCheck)])
        return self._pythonFileList

    def getTextFiles(self):
        """
        get method for list of text files
        """
        self.log(["found %d text files in %s"%(len(self._txtFileList), self._directoryForCompare)])
        return self._txtFileList
   
    def getFileNameFromPath(self, filePath):
        """
        Extract the file name from the file path
       
        <at> param  filePath        File path for the python file.
        <at> return                 File name
        """
        path, file = os.path.split(filePath)
        return file
       
   

    def stripFile(self, filetostrip):
        """
        Strips Python files of "#> " commenting
        and removes the code, writes out to a stripped file
        """
        print "\n" + "stripFile is executed" + "\n"
        print ("\n" + filetostrip)
        fh = open(filetostrip, "r")
        filelines = fh.readlines()      
       
        filetostrip = filetostrip.rstrip("py")
        filetostrip = (filetostrip + "strp")
        strippedfile = open(filetostrip, "w")
       
        for thisline in filelines:
            if thisline.startswith ("#> "):
                thisline.lstrip("#> ")
                strippedfile.write(thisline + "\n")
        strippedfile.close()
        fh.close()
 
    def compStripToTxt(self, origfile, strippedfile):
        """
        Compares the stripped Python header file
        to the original text of a test
        """
        print "compStripToTxt is executed"
        orig = open(origfile, "r")
        stripped = open(strippedfile, "r")
       
        origentry = orig.readlines()
        strippedentry = stripped.readlines()
        orig.close()
        stripped.close()
       
        if origentry != strippedentry:
            d = difflib.Differ()
            variance = list(d.compare(origentry, strippedentry))
            print variance
            return variance
        else:
            return None
            
               
       
    def log(self, linesToLog):
        """
        Log the script output to a file - echo to the console.
       
        <at> param  linesToLog     List of strings to write out
        """
       
        # if we have a output file write to it
        if self._outputFileName != None:
            outputFile = open(self._outputFileName, "a")
           
            if len(linesToLog) == 0:
                outputFile.write("\n")
               
            for line in linesToLog:
                outputFile.write(line + "\n")
               
            outputFile.close()
           
        # output to shell
        if len(linesToLog) == 0:
            print
        for line in linesToLog:
            print line

######################################
#MAIN SECTION
######################################

if __name__ == "__main__":
    checker = HeaderChecker(sys.argv[1], sys.argv[2], sys.argv[3])
   
    pythonFileList = checker.getValidPythonFiles ()
    checker.log([])
    checker.log(pythonFileList)
   
    #For all files in the list of Python files, strip the files of the header
    #comments markings
    changes = []
    for text in checker._txtFileList:
        file1 = checker.getFileNameFromPath(text)
        for pyfile in pythonFileList:
            file2 = checker.getFileNameFromPath(pyfile)
            print "comparing %s to %s"%(file1[:-4], file2[:-3])
            if file1[:-4] == file2[:-3]:
                print "matched %s to %s"%(file1[:-4], file2[:-3])
                pytostrip = checker._directoryToCheck + "\\" + file2
                print pytostrip
                stripped = checker.stripFile(pytostrip)
                print stripped
                #print "\n" + stripped + "\n"
                diff =checker.compStripToTxt(text, stripped)
                print diff
                if diff:
                   # changes.append(diff)
                    print changes
                    break
           
           

Now, I have a lot of print statements in there for debugging purposes, but I don't understand why when I run it, and it parses through my input directory and comparison directory it returns this

None
compStripToTxt is executed
Traceback (most recent call last):
  File "HeaderChecker.py", line 182, in ?
    diff =checker.compStripToTxt(text, stripped)
  File "HeaderChecker.py", line 114, in compStripToTxt
    stripped = open(strippedfile, "r")
TypeError: coercing to Unicode: need string or buffer, NoneType found



Why is it returning the None type?

How can I fix this?


thanks
Max
--
Max Russell
Senior Test Engineer
Barco
Bonnington Bond, 2 Anderson Place, Edinburgh EH6 5NP, UK
Tel + 44 (0) 131 472 5731 Fax + 44 (0) 131 472 4799
www.barco.com

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Kent Johnson | 1 Mar 19:25 2006
Picon

Re: Non type object?

Max Russell wrote:
> None
> compStripToTxt is executed
> Traceback (most recent call last):
>   File "HeaderChecker.py", line 182, in ?
>     diff =checker.compStripToTxt(text, stripped)
>   File "HeaderChecker.py", line 114, in compStripToTxt
>     stripped = open(strippedfile, "r")
> TypeError: coercing to Unicode: need string or buffer, NoneType found
> 
> 
> 
> Why is it returning the None type?
> 
> How can I fix this?

It's because stripped is None in your main program, as the print 
statement shows. stripped is the value returned from stripFile(). Since 
stripFile() doesn't explicitly return anything, its return value is 
None. I think you want stripFile() to return the name of the stripped 
file, which is filetostrip.

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane