By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 1,995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

Can I learn Python on this forum

bartonc
Expert 5K+
P: 6,596
well could and would you help me out on how to get started and what I need to do? Basically can you help me write a program that will extract all images from the digital camera once it is hooked up into the USB port of my computer not the USB hub?
How much python do you know at this point?
Dec 23 '06 #1
Share this Question
Share on Google+
13 Replies


P: 32
How much python do you know at this point?

just started learning it, =] hehehe I know I'm pathetic, but I'm learning, I'm taking a computer programming class this year, but we are just now starting on Java and python at the end of the year, but from what i've heard Python is the best to use when programming....so I thought I'd try it out, I'm reading how to program in python as we speak, but could you still help me on how to get started?
Dec 23 '06 #2

bartonc
Expert 5K+
P: 6,596
just started learning it, =] hehehe I know I'm pathetic, but I'm learning, I'm taking a computer programming class this year, but we are just now starting on Java and python at the end of the year, but from what i've heard Python is the best to use when programming....so I thought I'd try it out, I'm reading how to program in python as we speak, but could you still help me on how to get started?
Yeah, we'll help you get started. Just not started talking to hardware. Python is by far the easiest way to program your computer, but there are many things you need to know in order to write a program that talks to many systems (files, display, USB, etc.). Once you can read and write files and do work on those (copy a file from one directory to another would be a good exercise) and then do it with a file dialog box, and so on. Do you see where I'm going with all this?
Dec 23 '06 #3

P: 32
Yeah, we'll help you get started. Just not started talking to hardware. Python is by far the easiest way to program your computer, but there are many things you need to know in order to write a program that talks to many systems (files, display, USB, etc.). Once you can read and write files and do work on those (copy a file from one directory to another would be a good exercise) and then do it with a file dialog box, and so on. Do you see where I'm going with all this?

Yes I do could you help me get started on how to do it? like the exercise that you told me? Right now I am reading this http://swaroopch.info/text/Byte_of_Python:Control_Flow It seems to be pretty good so far. Is this any good?
Dec 23 '06 #4

bartonc
Expert 5K+
P: 6,596
Yes I do could you help me get started on how to do it? like the exercise that you told me? Right now I am reading this http://swaroopch.info/text/Byte_of_Python:Control_Flow It seems to be pretty good so far. Is this any good?
Yep. That looks like a good starting place.
Dec 23 '06 #5

P: 32
Yep. That looks like a good starting place.
ok can you help me out

so I am in the process of baking up a file using python, but it never works here it is:
Expand|Select|Wrap|Line Numbers
  1. import os, time
  2.  
  3. # 1. The files and directories to be backed up are specified in a list.
  4. source = [r'I:\']
  5. # If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that
  6.  
  7. # 2. The backup must be stored in a main backup directory.
  8. target_directory = 'C:\\'
  9.  
  10. # 3. The files are backed up into a zip file.
  11. # 4. The name of the zip archive is the current date and time
  12. target = target_directory + time.strftime('%Y%m%d_%H%M%S') + '.zip'
  13.  
  14. # 5. We use the standard ``zip`` command to put the files in a zip archive
  15. zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
  16. print zip_command
  17.  
  18. # Run the backup
  19. if os.system(zip_command) == 0:
  20.     print 'Successful backup to', target
  21. else:
  22.     print 'Backup FAILED'
and I don't see why it doesn't work, it comes back Backup failed..but why?
Dec 23 '06 #6

bartonc
Expert 5K+
P: 6,596
ok can you help me out

so I am in the process of baking up a file using python, but it never works here it is:
Expand|Select|Wrap|Line Numbers
  1. import os, time
  2.  
  3. # 1. The files and directories to be backed up are specified in a list.
  4. source = [r'I:\']
  5. # If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that
  6.  
  7. # 2. The backup must be stored in a main backup directory.
  8. target_directory = 'C:\\'
  9.  
  10. # 3. The files are backed up into a zip file.
  11. # 4. The name of the zip archive is the current date and time
  12. target = target_directory + time.strftime('%Y%m%d_%H%M%S') + '.zip'
  13.  
  14. # 5. We use the standard ``zip`` command to put the files in a zip archive
  15. zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
  16. print zip_command
  17.  
  18. # Run the backup
  19. if os.system(zip_command) == 0:
  20.     print 'Successful backup to', target
  21. else:
  22.     print 'Backup FAILED'
and I don't see why it doesn't work, it comes back Backup failed..but why?
Is it really your intention to zip the entire I drive contents????
You should really start smaller like we have already discussed.

This script calls your system cmd.exe so you are already complicating things.

You need two things on you system for this to work. 1) an "I" drive, and 2) zip installed on the system PATH. If you don't know how to run zip from the command line, you are starting of with too many unknowns. If you can run zip from the command line, try to do the zip by hand. That will tell you if that part is working. If it is, then we can work on your script.
Think "baby steps". You tend to jump into the deep end a lot.
Dec 23 '06 #7

P: 32
Is it really your intention to zip the entire I drive contents????
You should really start smaller like we have already discussed.

This script calls your system cmd.exe so you are already complicating things.

You need two things on you system for this to work. 1) an "I" drive, and 2) zip installed on the system PATH. If you don't know how to run zip from the command line, you are starting of with too many unknowns. If you can run zip from the command line, try to do the zip by hand. That will tell you if that part is working. If it is then we can work on your script.
Think "baby steps". You tend to jump into the deep end a lot.
ok so wait lets say I take the zip thing out, now the I drive is my flash drive that is plugged in and it only has like 3 files on it right now which are small, but what I am trying to do is back the SD folder on my I drive up to the C drive in a folder called drivers.... so my code now is


import os, time

# 1. The files and directories to be backed up are specified in a list.
source = [r'I:\SD']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that

# 2. The backup must be stored in a main backup directory.
target_directory = r'C:\Drivers'

and it still doesn't work, what am I doing wrong, do you have AIM or something so I can communicate with you easier?
Dec 23 '06 #8

bartonc
Expert 5K+
P: 6,596
ok so wait lets say I take the zip thing out, now the I drive is my flash drive that is plugged in and it only has like 3 files on it right now which are small, but what I am trying to do is back the SD folder on my I drive up to the C drive in a folder called drivers.... so my code now is


import os, time

# 1. The files and directories to be backed up are specified in a list.
source = [r'I:\SD']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that

# 2. The backup must be stored in a main backup directory.
target_directory = r'C:\Drivers'

and it still doesn't work, what am I doing wrong, do you have AIM or something so I can communicate with you easier?
I think that you are still aiming a little too high, for now. In order to work with path names, you'll need to have good string manipulation skills. This is very basic and easy to learn, but path names have many more issues (is it file? is it a folder?, etc.)
In #1 above, there is a list of strings (Ok, only one string in the list) so you need to know how lists work, too.
Pick something fun and interesting and easy to start with. The most common first program is "hello world". I'll start very simple and add to it as we go along. OK?

Expand|Select|Wrap|Line Numbers
  1. # this is a comment. you write notes about what the lines below do
  2. # This program prints "hello world" ten times
  3. # using a for loop over a list of integers
  4. # the list of integers is generated by the built-in function: range()
  5. # blank lines are a really good thing to make your code readable
  6.  
  7. for i in range(10):    # the colon says 'the indented lines below belong to the for
  8.     print "hello world"
  9.  
  10. # In this example, there are 2 built-in operators and 2 built-in functions
  11. # and a string object. Can you pick out the functions from the operators?
Dec 23 '06 #9

P: 32
I think that you are still aiming a little too high, for now. In order to work with path names, you'll need to have good string manipulation skills. This is very basic and easy to learn, but path names have many more issues (is it file? is it a folder?, etc.)
In #1 above, there is a list of strings (Ok, only one string in the list) so you need to know how lists work, too.
Pick something fun and interesting and easy to start with. The most common first program is "hello world". I'll start very simple and add to it as we go along. OK?

Expand|Select|Wrap|Line Numbers
  1. # this is a comment. you write notes about what the lines below do
  2. # This program prints "hello world" ten times
  3. # using a for loop over a list of integers
  4. # the list of integers is generated by the built-in function: range()
  5. # blank lines are a really good thing to make your code readable
  6.  
  7. for i in range(10):    # the colon says 'the indented lines below belong to the for
  8.     print "hello world"
  9.  
  10. # In this example, there are 2 built-in operators and 2 built-in functions
  11. # and a string object. Can you pick out the functions from the operators?

Yea I already did hello world as the first thing

i= 'hello world'
print i

but yea I'm kind of trying to make a back up a folder and back up files program could you teach me how to do it, because I really don't have much time to learn this stuff I somehow need to get that usb program done..so i was thinking about starting off with backing up files, do you know how its done?
Dec 23 '06 #10

bartonc
Expert 5K+
P: 6,596
Yea I already did hello world as the first thing

i= 'hello world'
print i

but yea I'm kind of trying to make a back up a folder and back up files program could you teach me how to do it, because I really don't have much time to learn this stuff I somehow need to get that usb program done..so i was thinking about starting off with backing up files, do you know how its done?
I will show you when you can answer the question in the last post correctly.
Please slow down a little and try again.
Dec 23 '06 #11

P: 32
I will show you when you can answer the question in the last post correctly.
Please slow down a little and try again.

I'm sorry about the lack of information, well what I am trying to do is make a backup of a folder and place the backup in another directory. Does that answer the question?
Dec 23 '06 #12

Expert 100+
P: 1,892
Python is by far the easiest way to program your computer, but there
Barton do you think so? What editor do you use to create python programs? I'm interested in learning a new language.
Dec 23 '06 #13

bartonc
Expert 5K+
P: 6,596
Barton do you think so? What editor do you use to create python programs? I'm interested in learning a new language.
Yes! Especially if you know C or C++, picking up python is a snap. The syntax is very natural and doesn't have all those parentheses and required semi-colons that always confused me in C. The really cool thing is interactive testing with the interpreter (shell) that lets you type in a line of code and see the results imediately. Dynamic Typing is also very cool. It lets you pass any type of argument to a function. Then the function can do different things based on the type of the argument(s). Many cool features, lots of libraries, great language!
Keep posting,
Barton

PS Get an avatar so that I can see who's posting (dang it).
Dec 23 '06 #14

Post your reply

Sign in to post your reply or Sign up for a free account.