剧本讨论&批判 [英] Script Discussion & Critique

查看:47
本文介绍了剧本讨论&批判的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个论坛可以发布一个Python脚本并让它受到其他人的批评?


类似:Y会更有效率你是这样做的,或者这样做可能会导致X等问题。


谢谢!!!

Is there a forum where one could post a Python script and have it
critiqued by others?

Something like: Y would be more efficent if you did it this way, or
doing it that way could cause problems with X, etc.

Thanks!!!

推荐答案

这里将做


2003年8月27日星期三18:33:21 -0400,hokiegal99< ho********@hotmail.com>写道:
here will do

On Wed, 27 Aug 2003 18:33:21 -0400, hokiegal99 <ho********@hotmail.com> wrote:
是否有一个论坛可以发布一个Python脚本并让其他人批评它?

类似的东西:Y会是如果你这样做会更有效率,或者这样做可能会导致X等问题。

谢谢!!!
Is there a forum where one could post a Python script and have it
critiqued by others?

Something like: Y would be more efficent if you did it this way, or
doing it that way could cause problems with X, etc.

Thanks!!!






derek / nul写道:
derek / nul wrote:
这里会做




好​​的,我有几个问题关于此消息末尾的脚本:


这个脚本编写得好吗?这是一个好的设计吗?如何才能更好地(>写一个文件正好scipt所做的文件)?我希望使用

来递归查找所有类型文件中的替换字符串(二进制

和文本)。


感谢任何想法,指示或批评...脚本来自列表后面的大部分想法



#感谢comp.lang.python

import os,string

print"

打印************************************* ************ *****"

print"递归查找和替换的三个简单步骤

打印**************************** ********************* *****"

print"

x = raw_input(" 1.输入您要查找的字符串:")

print"

y = raw_input(" 2.您希望将%s替换为:"%x)

print"

setpath = raw_input(" 3.输入prgroam应运行的路径:)

print"

for root,dirs,os.walk中的文件(setpath):

fname = files

for fname in files:

inputFile = file(os.path.join(root,fname),''r'')

data = inputFile.read()

inputFile.close()

search = string.find(data,x)

如果搜索> = 1:

data = data。 replace(x,y)

outputFile = file(os.path.join(root,fname),''w'')

outputFile.write(data)

outputFile.close()

print" Replacing",x," with",y," in",fname

print "

print" **********"

print"完成

打印**********"

print"



OK, I have a few questions about the script at the end of this message:

Is this script written well? Is it a good design? How could it be made
better (i.e. write to a file exactly what the scipt did)? I hope to use
it to recursively find a replace strings in all types of files (binary
and text).

Thanks for any ideas, pointers or critique... most of the ideas behind
the script came from the list.
#Thanks to comp.lang.python
import os, string
print " "
print "************************************************* *****"
print " Three Easy Steps to a Recursive find and Replace "
print "************************************************* *****"
print " "
x = raw_input("1. Enter the string that you''d like to find: ")
print " "
y = raw_input("2. What would you like to replace %s with: " %x)
print " "
setpath = raw_input("3. Enter the path where the prgroam should run: ")
print " "
for root, dirs, files in os.walk(setpath):
fname = files
for fname in files:
inputFile = file(os.path.join(root,fname), ''r'')
data = inputFile.read()
inputFile.close()
search = string.find(data, x)
if search >=1:
data = data.replace(x, y)
outputFile = file(os.path.join(root,fname), ''w'')
outputFile.write(data)
outputFile.close()
print "Replacing", x, "with", y, "in", fname
print " "
print "**********"
print " Done "
print "**********"
print " "


我发现有关这个脚本的奇怪之处在于它不会在
替换字符串文本文件的最左侧*除非*字符串

前面有一个或多个空格。例如:


这个(不会被替换掉)

这个(将替换为THAT)

这个(将替换为THAT)

这个(将替换为THAT)

Something odd that I''ve discovered about this script is that it won''t
replace strings at the far left side of a text file *unless* the string
has one or more spaces before it. For example:

THIS (won''t be replace with THAT)
THIS (will be replaced with THAT)
THIS (will be replaced with THAT)
THIS (will be replaced with THAT)

#Thanks to comp.lang.python
import os,string
print"
打印***************************************** ******** *****"
打印递归查找和替换
打印的三个简单步骤******************************** ***************** *****"
打印
x = raw_input(" 1.输入您要查找的字符串:")
print"
y = raw_input(" 2.您希望将%s替换为:"%x)
print"
setpath = raw_input(" 3.输入prgroam应运行的路径:)
print"对于root,dirs,os.walk中的文件(setpath):
fname = files
对于文件中的fname:
inputFile = file(os.path.join( root,fname),''r'')
data = inputFile.read()
inputFile.close()
search = string.find(data,x)
if search> = 1:
data = data.replace(x,y)
outputFile = file(os.path.join(root,fname),''w'')
outputFile .write(data)
outputFile.close()
print" Replacing",x," with",y," in",fname
print"
打印**********"
打印"完成
打印**********"
print"
#Thanks to comp.lang.python
import os, string
print " "
print "************************************************* *****"
print " Three Easy Steps to a Recursive find and Replace "
print "************************************************* *****"
print " "
x = raw_input("1. Enter the string that you''d like to find: ")
print " "
y = raw_input("2. What would you like to replace %s with: " %x)
print " "
setpath = raw_input("3. Enter the path where the prgroam should run: ")
print " "
for root, dirs, files in os.walk(setpath):
fname = files
for fname in files:
inputFile = file(os.path.join(root,fname), ''r'')
data = inputFile.read()
inputFile.close()
search = string.find(data, x)
if search >=1:
data = data.replace(x, y)
outputFile = file(os.path.join(root,fname), ''w'')
outputFile.write(data)
outputFile.close()
print "Replacing", x, "with", y, "in", fname
print " "
print "**********"
print " Done "
print "**********"
print " "



这篇关于剧本讨论&amp;批判的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆