[Python] вопрос/ответ.

Discussion in 'Python' started by De-visible, 21 Jan 2009.

  1. Велемир

    Joined:
    19 Jun 2006
    Messages:
    1,123
    Likes Received:
    96
    Reputations:
    -25
    Пасип:),буду знать )
     
  2. Велемир

    Joined:
    19 Jun 2006
    Messages:
    1,123
    Likes Received:
    96
    Reputations:
    -25
    Народ,а как в Python инициализировать запуск процесса какой-то программый,к примеру,paint или user.zip и получить к нему доступ,если возможно)
     
  3. login999

    login999 Elder - Старейшина

    Joined:
    12 Jun 2008
    Messages:
    491
    Likes Received:
    280
    Reputations:
    92
    http://docs.python.org/library/os.html

    Code:
    os.startfile(path[, operation])
    
    Start a file with its associated application.
    
    When operation is not specified or 'open', this acts like double-clicking the file in Windows Explorer, or giving the file name as an argument to the start command from the interactive command shell: the file is opened with whatever application (if any) its extension is associated.
    
    When another operation is given, it must be a “command verb” that specifies what should be done with the file. Common verbs documented by Microsoft are 'print' and 'edit' (to be used on files) as well as 'explore' and 'find' (to be used on directories).
    
    startfile() returns as soon as the associated application is launched. There is no option to wait for the application to close, and no way to retrieve the application’s exit status. The path parameter is relative to the current directory. If you want to use an absolute path, make sure the first character is not a slash ('/'); the underlying Win32 ShellExecute function doesn’t work if it is. Use the os.path.normpath() function to ensure that the path is properly encoded for Win32. Availability: Windows.
    
    Code:
    import os
    os.startfile("C:\Python26\python.exe")
    
    ^^^^^
    Пример как запустить программу.
    А если ты хочешь, чтобы он тебе еще и нарисовал что-нибудь, то лучше юзай для этих целей AutoIt (http://www.autoitscript.com/autoit3/index.shtml)
     
  4. yarbabin

    yarbabin HACKIN YO KUT

    Joined:
    21 Nov 2007
    Messages:
    1,663
    Likes Received:
    916
    Reputations:
    363
    Code:
    a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9']
    for i in range(len(a)):
     print a[i]
    как сделать что бы буквы складывались? типо:
    Code:
    aa
    ab
    ac
    ad
    ...
    ba
    bb
    bc
    ...
    za
    zb
    потом:
    Code:
    aaa
    aab
    ...
    aba
    abb
    ...
    zaa
    zab
    ну и каждый раз по одной букве
     
    _________________________
  5. Chaak

    Chaak Elder - Старейшина

    Joined:
    1 Jun 2008
    Messages:
    1,059
    Likes Received:
    1,067
    Reputations:
    80
    Code:
    from __future__ import generators
    
    a = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
             'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
             '1','2','3','4','5','6','7','8','9'
    ]
    
    def xcombinations(items, n):
        if n==0: yield []
        else:
            for i in xrange(len(items)):
                for cc in xcombinations(items[:i]+items[i+1:],n-1):
                    yield [items[i]]+cc
     
    def xuniqueCombinations(items, n):
        if n==0: yield []
        else:
            for i in xrange(len(items)):
                for cc in xuniqueCombinations(items[i+1:],n-1):
                    yield [items[i]]+cc
     
    def xselections(items, n):
        if n==0: yield []
        else:
            for i in xrange(len(items)):
                for ss in xselections(items, n-1):
                    yield [items[i]]+ss
     
    def xpermutations(items):
        return xcombinations(items, len(items))
    
    if __name__=="__main__":
            for p in xpermutations(a):
                print ''.join(p)
    
    Как-то так
     
    #25 Chaak, 6 Feb 2009
    Last edited by a moderator: 6 Feb 2009
    2 people like this.
  6. yarbabin

    yarbabin HACKIN YO KUT

    Joined:
    21 Nov 2007
    Messages:
    1,663
    Likes Received:
    916
    Reputations:
    363
    как подсчитать кол-во строк, например в txt файле?
     
    _________________________
  7. De-visible

    De-visible [NDC] Network develope c0ders

    Joined:
    6 Jan 2008
    Messages:
    916
    Likes Received:
    550
    Reputations:
    66

    Code:
    filehandle = open("myfile", 'r')
    print len(filehandle.readlines())
    filehandle.close()

    Code:
    Filehandle =open ("myfile", 'r')
    count = 0
    while filehandle.readline ()! = " ":
            count = count + 1
    print count
    Filehandle.close ()
     
    1 person likes this.
  8. yarbabin

    yarbabin HACKIN YO KUT

    Joined:
    21 Nov 2007
    Messages:
    1,663
    Likes Received:
    916
    Reputations:
    363
    реально ли, в питоне создать хэш DES, mysql и др.?
    md5 и sha1 ненадо.
     
    _________________________
  9. De-visible

    De-visible [NDC] Network develope c0ders

    Joined:
    6 Jan 2008
    Messages:
    916
    Likes Received:
    550
    Reputations:
    66
    Конечно, и это кстати сделано до нас...
     
  10. yarbabin

    yarbabin HACKIN YO KUT

    Joined:
    21 Nov 2007
    Messages:
    1,663
    Likes Received:
    916
    Reputations:
    363
    да, но какими модулями? в хэшлиб не нашел.
    если можно, пример.
     
    _________________________
  11. De-visible

    De-visible [NDC] Network develope c0ders

    Joined:
    6 Jan 2008
    Messages:
    916
    Likes Received:
    550
    Reputations:
    66
    Примеры в гуглах,

    http://twhiteman.netfirms.com/des.html
    http://mail.python.org/pipermail/python-list/2008-December/520889.html
    Вообщем если поискать можно найти.
     
    1 person likes this.
  12. any.zicky

    any.zicky New Member

    Joined:
    15 Jan 2009
    Messages:
    2
    Likes Received:
    1
    Reputations:
    0
    pyCrypto
     
    1 person likes this.
  13. yarbabin

    yarbabin HACKIN YO KUT

    Joined:
    21 Nov 2007
    Messages:
    1,663
    Likes Received:
    916
    Reputations:
    363
    какими модулями считывать хеадеры страниц? лучше с примером.
     
    _________________________
  14. login999

    login999 Elder - Старейшина

    Joined:
    12 Jun 2008
    Messages:
    491
    Likes Received:
    280
    Reputations:
    92
    urllib2.urlopen(request).info()
     
  15. De-visible

    De-visible [NDC] Network develope c0ders

    Joined:
    6 Jan 2008
    Messages:
    916
    Likes Received:
    550
    Reputations:
    66
    urllib.urlopen("http:// ...").info
     
  16. gold-goblin

    gold-goblin Elder - Старейшина

    Joined:
    26 Mar 2007
    Messages:
    917
    Likes Received:
    174
    Reputations:
    3
    подскажите почему функция time.clock() возвращает 0.1 сикунды?
    хоть в системе (linux) часы идут правельно
     
  17. eLWAux

    eLWAux Elder - Старейшина

    Joined:
    15 Jun 2008
    Messages:
    860
    Likes Received:
    616
    Reputations:
    211
    http://docs.python.org/library/time.html

    >>> from time import gmtime, strftime
    >>> strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
    'Thu, 28 Jun 2001 14:17:15 +0000'
     
  18. gold-goblin

    gold-goblin Elder - Старейшина

    Joined:
    26 Mar 2007
    Messages:
    917
    Likes Received:
    174
    Reputations:
    3
    eLWAux
    мне надо именно секунды от 1970 года.
    их можно получить командой time.clock() но она возвращает 0.1
    питон не может получить время от системы =(
     
  19. .xs

    .xs Member

    Joined:
    2 Jul 2008
    Messages:
    24
    Likes Received:
    16
    Reputations:
    3
    <type 'float'>
    На всякий случай:
     
  20. ph1l1ster

    ph1l1ster Elder - Старейшина

    Joined:
    11 Mar 2008
    Messages:
    396
    Likes Received:
    153
    Reputations:
    19
    Помогите установить python-pexpect модуль в винде.

    скачиваю - http://pexpect.sourceforge.net/pexpect-2.3.tar.gz

    прописываю setup.py install но всё равно не устанавливает.