我使用的是Windows 7和python 2.7.我想将日志文件大小限制为5MB.我的应用程序在启动时写入日志文件,然后应用程序终止.当我的应用程序再次启动时,它将写入相同的日志文件.因此app不会持续运行.应用程序启动,处理和终止.
我的日志记录代码是:
import logging
import logging.handlers
logging.basicConfig(filename=logfile.log, level="info", format='%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
logging.info("*************************************************")
Run Code Online (Sandbox Code Playgroud)
我尝试使用RotatingFileHandler但它没有用
logging.handlers.RotatingFileHandler(logFile, mode='a', maxBytes=5*1024*1024, backupCount=2, encoding=None, delay=0)
Run Code Online (Sandbox Code Playgroud)
那么,我如何在python中强制执行文件大小限制?
我正在使用Windows上的python 2.7和keyring-3.2.1创建一个应用程序.在我的eclipse上的python代码中,我使用了
import keyring
keyring.set_password("service","jsonkey",json_res)
json_res= keyring.get_password("service","jsonkey")
Run Code Online (Sandbox Code Playgroud)
工作正常,因为我在密钥环中存储json响应.但是,当我使用py2exe将python代码转换为exe时,它会在制作dist时显示导入错误密钥环.请建议如何在py2exe中包含密钥环.
Traceback (most recent call last):
File "APP.py", line 8, in <module>
File "keyring\__init__.pyc", line 12, in <module>
File "keyring\core.pyc", line 15, in <module>
File "keyring\util\platform_.pyc", line 4, in <module>
File "keyring\util\platform.pyc", line 29, in <module>
AttributeError: 'module' object has no attribute 'system'
Run Code Online (Sandbox Code Playgroud)
platform_.py代码是:
from __future__ import absolute_import
import os
import platform
def _data_root_Windows():
try:
root = os.environ['LOCALAPPDATA']
except KeyError:
# Windows XP
root = os.path.join(os.environ['USERPROFILE'], 'Local Settings')
return os.path.join(root, 'Python …
Run Code Online (Sandbox Code Playgroud) 在Windows 7 64位机器上使用python 2.7.
如何获取文件关闭事件:
那么,如何在上述情况下获取文件关闭事件?是否可以通过公共代码实现上述情况?我正在处理不同的文件类型
我在python中创建一个需要存储密钥的应用程序.我使用密钥环模块来存储密钥.我使用python-2.7和osx 10.8.5与密钥环3.2(easy_install密钥环).代码在eclipse上正常运行,但是当我使用py2app将代码转换为应用程序时,它显示错误的MYAPP错误打开控制台终止
import keyring
keyring.set_password("title","section","keys")
res= keyring.get_password("title","section")
Run Code Online (Sandbox Code Playgroud)
我在键入"python setup.py py2app"时包含终端响应废料,同时通过py2app制作dist
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/__init__.py to keyring/__init__.pyc
creating /Users/fis/Desktop/build/bdist.macosx-10.8-intel/python2.7-semi_standalone/app/collect/keyring
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/backend.py to keyring/backend.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/core.py to keyring/core.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/errors.py to keyring/errors.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/getpassbackend.py to keyring/getpassbackend.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/py27compat.py to keyring/py27compat.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/util/__init__.py to keyring/util/__init__.pyc
creating /Users/fis/Desktop/build/bdist.macosx-10.8-intel/python2.7-semi_standalone/app/collect/keyring/util
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/util/platform_.py to keyring/util/platform_.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/util/properties.py to keyring/util/properties.pyc
byte-compiling /Library/Python/2.7/site-packages/pathtools-0.1.2-py2.7.egg/pathtools/__init__.pyc to pathtools/__init__.pyc
creating /Users/fis/Desktop/build/bdist.macosx-10.8-intel/python2.7-semi_standalone/app/collect/pathtools
Run Code Online (Sandbox Code Playgroud) 我正在使用mac osx 10.8.5在python中创建一个应用程序我通过使用将python脚本转换为应用程序py2app
.但是,在app中,On Show Package Contents-->Contents-->Resources
原始代码存在.我不希望通过分发我的应用程序作为安全问题来向其他人显示我的代码.我用(.pyc)代码删除了(.py)代码,在这种情况下,应用程序无法正常工作.请为它提供一些方法.我也搜索其他问题,但没有得到预期的结果.我的setup.py是
from setuptools import setup
APP=['myapp.py']
DATA_FILES= [('',['config.cfg'])]
OPTIONS={'iconfile':'cc.icns','argv_emulation': True,'plist':{'CFBundleShortVersionString':'1.0'}}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app']
)
Run Code Online (Sandbox Code Playgroud) 我正在使用 windows 7 和 python 2.7 我想将 172.16.45.84 IP 地址映射到 myapp.nobies.in 而不映射到主机文件中。
我有这个主机名所需的证书。我不想在主机文件中映射,因为它需要管理权限。
那么,如何为它创建一个 DNS python 服务器,它可以随我的应用程序一起提供。
我正在使用气球弹出通知来显示用户通知消息。它仅持续5秒钟,因为默认情况下,Windows通知设置显示5秒钟的时间。
我的代码是:
from win32api import *
from win32con import NULL
from win32gui import *
import win32com.client as com
import win32con
import win32file
import time
class WindowsBalloonTip:
def __init__(self, title, msg,notlivelong):
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
}
# Register the Window class.
iconPathName= "D:\cc.ico"
wc = WNDCLASS()
hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbar"
wc.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = CreateWindow( classAtom, "Taskbar", …
Run Code Online (Sandbox Code Playgroud) 我在Python中使用以下代码打开了一个临时文件:
p=subprocess.Popen(tempFileName,shell=True)
processId=p.pidcode
Run Code Online (Sandbox Code Playgroud)
当该文件关闭时,我想删除该临时文件.我想用打开过程的PiD删除该文件,但问题是即使我关闭该文件pid仍然存在.
p=subprocess.Popen(tempFileName,shell=True)
processId=p.pid
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以删除该临时文件?
如何在mac上制作一个简单的弹出气球消息。我不想使用 NSUserNotification。使用 python-2.7 和 osx 10.8.5。POP-UP 不应该有任何按钮。弹出窗口应该来,显示消息并自动去。它也应该与 py2app 正确打包。
import objc
import Foundation
import AppKit
def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
notification = NSUserNotification.alloc().init()
notification.setTitle_(title)
notification.setSubtitle_(subtitle)
notification.setInformativeText_(info_text)
notification.setUserInfo_(userInfo)
if sound:
notification.setSoundName_("NSUserNotificationDefaultSoundName")
notification.setDeliveryDate_(Foundation.NSDate.dateWithTimeInterval_sinceDate_(delay, Foundation.NSDate.date()))
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
def notificationBalloon(title,msg):
notify(title1, msg1,"", sound=False)
Run Code Online (Sandbox Code Playgroud) python ×10
macos ×4
windows ×3
process ×2
python-2.7 ×2
applescript ×1
dns ×1
file ×1
filehandler ×1
hosts-file ×1
json ×1
log-files ×1
logging ×1
popup ×1
py2app ×1
py2exe ×1
pywin32 ×1
ssl ×1
winapi ×1