在Python中接受文件参数(从“发送到"上下文菜单中) [英] Accepting File Argument in Python (from Send To context menu)
问题描述
我首先要指出我几乎没有python经验.
I'm going to start of by noting that I have next to no python experience.
替代文字http://www.aquate.us/u/9986423875612301299.jpg
您可能知道,只需在Windows PC上的发送到"文件夹中放置一个快捷方式,就可以允许程序将文件作为参数.
As you may know, by simply dropping a shortcut in the Send To folder on your Windows PC, you can allow a program to take a file as an argument.
我将如何编写一个以该文件为参数的python程序?
How would I write a python program that takes this file as an argument?
而且,如果有人有机会,这是一种奖励- 如何将其与urllib2集成以将文件发布到服务器上的PHP脚本中?
And, as a bonus if anyone gets a chance -- How would I integrate that with a urllib2 to POST the file to a PHP script on my server?
谢谢.
编辑-同样,如何使某些内容显示在发送至"菜单中?我的印象是,您只需将快捷方式放到SendTo文件夹中,它会自动在菜单中添加一个选项... 没关系.我发现自己在做什么错了:)
Edit-- also, how do I make something show up in the Sendto menu? I was under the impression that you just drop a shortcut into the SendTo folder and it automatically adds an option in the menu... Never mind. I figured out what I was doing wrong :)
推荐答案
- 找出所拖动的文件是什么: http://docs.python. org/library/sys.html#sys.argv
- 打开它: http://docs.python.org/library/functions.html #open
- 在以下位置阅读: http://docs.python.org/library/stdtypes.html#file.read
- 发布它: http://docs.python.org/library/urllib2 .html#urllib2.urlopen
- Find out what the dragged file was: http://docs.python.org/library/sys.html#sys.argv
- Open it: http://docs.python.org/library/functions.html#open
- Read it in: http://docs.python.org/library/stdtypes.html#file.read
- Post it: http://docs.python.org/library/urllib2.html#urllib2.urlopen
这篇关于在Python中接受文件参数(从“发送到"上下文菜单中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!