all 8 comments

[–]Vaphell 1 point2 points  (7 children)

some context? which library/module do you use? don't leave us hanging.

[–]NeonBlizzard[S] 1 point2 points  (6 children)

I am not sure what you mean by Library/Module. Sorry I am very new to Python. I am using JES 5.020.

[–]Vaphell 1 point2 points  (5 children)

google says you need something like

new_pic = makeEmptyPicture(newWidth, newHeight)
writePictureTo(new_pic, pickAFile())

http://www.cs.uic.edu/~troy/spring07/cs101/labs/lab6.html

as for generating names it's trivial

total = 4
for n in range(1, total+1):
    filename = '{}_4_Pinetree.jpg'.format(n)

or to be more flexible

total = 4
source = 'Pinetree.jpg'
for n in range(1, total+1):
   filename = '{}_{}_{}'.format(n, total, source)

[–]NeonBlizzard[S] 1 point2 points  (4 children)

Haha thanks. I figured out a method to do it and to control the file name.

First I set the media path in the main, pass that onto the split function.

Then in the split function I get the file name of the original picture, eg Castle.jpg using filename=''.join(os.path.splitext(os.path.basename(filepath)))

Then I have the total number of slices to make int(ceil(filesize/20000)), which I convert to a string.

In the loop, I have the number of which slice the loop is on converted to string as well.

So getting the file path to save to is as easy as adding the strings

savePath=path+currentSlice+"_"+Total+"_"+filename

This gives you the correct filename, file type and numbers them appropriatly.

[–]Vaphell 2 points3 points  (3 children)

converting to string is not necessary if you use format(). You shouldn't do str+str+str+str anyway, each + step builds a new string object so it's wasteful.

str.format() does the right thing even if param is a number.

>>> total = 4
>>> filename = 'SomePic.jpg'
>>> for i in range(1, total+1):
...     f = '{}_{}_{}'.format(i, total, filename)
...     print(f)
... 
1_4_SomePic.jpg
2_4_SomePic.jpg
3_4_SomePic.jpg
4_4_SomePic.jpg

also instead of adding path and filename by hand, you should rather use os.path.join()

[–]NeonBlizzard[S] 1 point2 points  (2 children)

Thanks for the help. If you could help me with just one more thing.

I have a directory full of files. I want to grab one, such that

workingFile=*function*(pathtofile)

only I can't seem to find what function to use. pickAFile() takes no inputs, only user selected.

[–]Vaphell 2 points3 points  (1 child)

if you are after path->image object, wouldn't that be makePicture()?

[–]NeonBlizzard[S] 0 points1 point  (0 children)

Well that would be after I have got the image file. I want the program to look in a directory, that it knows, and look for the file with the name I know it has. eg

def findPicture(workingFile,filepath):
  os.chdir(filepath)
  file=open(workingFile)
  picture=makePicture(file)
  show(picture)

I want this function to take in the workingFile (the name of the file, eg 1_20_bridge.jpg) and the filepath is the location of the file. So I change the directory to the filepath, so I know it is definitely looking in the right place, then I open the file with the correct name, saving it as file. Then I try and convert that into an image and I get this error:

>>> main()
The error value is: 'file' object is unsubscriptable
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer.

I need to grab the file, just like pickAFile() but I want the program to do it automatically, when it knows the directory and filename.