Можно добавить атрибуты к функции и использовать ее в качестве статической переменной.
def myfunc():
myfunc.counter += 1
print myfunc.counter
# attribute must be initialized
myfunc.counter = 0
, С другой стороны, если Вы не хотите устанавливать переменную вне функции, можно использовать hasattr()
для предотвращения AttributeError
исключение:
def myfunc():
if not hasattr(myfunc, "counter"):
myfunc.counter = 0 # it doesn't exist yet, so initialize it
myfunc.counter += 1
Так или иначе статические переменные довольно редки, и необходимо найти лучшее место для этой переменной, скорее всего, в классе.
Перейдите в папку веб-сайта, затем запустите
zip -R foo '*.php' '*.html' '*.js' '*.css'
Вы также можете запустить это вне папки веб-сайта:
zip -r foo website_folder -i '*.php' '*.html' '*.js' '*.css'
You can use find
and grep
to generate the file list, then pipe that into zip
e.g.
find . | egrep "\.(html|css|js|php)$" | zip -@ test.zip
(-@
tells zip to read a file list from stdin)
Вот как я справился для этого, но мне также нравится версия ghostdog74.
tar -czvf archive.tgz `find test/ | egrep ".*\.html|.*\.php"`
Вы можете добавить дополнительные расширения, добавив их в регулярное выражение.
I liked Nick's answer, but, since this is a programming site, why not use Ant to do this. :)
Then you can put in a parameter so that different types of files can be zipped up.
You could write a shell script to copy files based on a pattern/expression into a new folder, zip the contents and then delete the folder. Now, as for the actual syntax of it, ill leave that to you :D.
you may want to use find(GNU) to find all your php,html etc files.then tar them up
find /path -type f \( -iname "*.php" -o -iname "*.css" -o -iname "*.js" -o -iname "*.ext" \) -exec tar -r --file=test.tar "{}" +;
after that you can zip it up