Jump to content

I Need Help With Python ...


rufus777
 Share

Recommended Posts

import os

#Pidgin-2.7.9 HTTP

os.system("wget http://sourceforge.net/projects/pidgin/files/Pidgin/2.7.9/pidgin-2.7.9.exe")

#Spotify HTTP

os.system("wget http://download.spotify.com/Spotify%20Installer.exe")

#Pidgin-2.7.9 Install

os.system("pidgin-2.7.9.exe")

#Spotify Install

os.system("spotify installer.exe") <------------- 'spotify' is not recognized as an internal or external command,

operable program or batch file.

How should I use "(space)" in os.system???

Link to comment
Share on other sites

You shouldn't make system calls if possible (they're evil), it's actually easy to download files in pure python.

Heres a quick example;

import urllib

from subprocess import Popen

path = 'C:\\file.exe'                      # Local path
url = 'http://remote-server.com/file.exe'  # Remote path

connection = urllib.urlopen(url)
remoteFile = connection.read()
connection.close()

try:
    localFile = open(path, 'w')
    localFile.write(remoteFile)
    localFile.close()
    Popen(path) # Execute whatever "path" points to
except IOError:
    print '***** OMFG ERROR: Location is not writable %s *****\n' % path

Using sys.argv you can even make the 'url' a command line argument.

Edited by sablefoxx
Link to comment
Share on other sites

  • 2 weeks later...

You shouldn't make system calls if possible (they're evil), it's actually easy to download files in pure python.

Heres a quick example;

import urllib

from subprocess import Popen

path = 'C:\\file.exe'                      # Local path
url = 'http://remote-server.com/file.exe'  # Remote path

connection = urllib.urlopen(url)
remoteFile = connection.read()
connection.close()

try:
    localFile = open(path, 'w')
    localFile.write(remoteFile)
    localFile.close()
    Popen(path) # Execute whatever "path" points to
except IOError:
    print '***** OMFG ERROR: Location is not writable %s *****\n' % path

Using sys.argv you can even make the 'url' a command line argument.

Just a suggestion, but instead of using all that code with urllib.urlopen() couldn't you just use urllib.urlretrieve() to grab the file instead? I tried your code on a picture and it jumbled up all the pixels. So this is what i came up with

import urllib

path="C:\\file.exe" #local path
url="http://www.example.com/file.exe" #remote path

urllib.urlretrieve(url,path)

It seems a lot simpler just to do this instead.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...