我希望ro接收一些通过VPN作为UDP数据包发送的数据.所以在python中编写(大部分是复制)这个程序:
import socket
import sys
HOST = ???????
PORT = 80
# SOCK_DGRAM is the socket type to use for UDP sockets
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((HOST,PORT))
data,addr = sock.recv(1024)
print "Received: %s" % data
print "Addr: %s" % addr
Run Code Online (Sandbox Code Playgroud)
我应该用什么作为主持人?我知道发件人的IP,但似乎任何不是本地的东西给了我socket.error:[Errno 10049].VPN给我的IP(发送方发送的IP相同,即)?还是只是localhost?
我对PIC汇编程序中的银行切换感到困惑......这适用于在usart上放置'Q':
bsf PORTB,1 ;Set Transmit DIR (PORTB (0x6) not mirrored in other banks)
movlw 'Q' ;'Q' to work reg
movwf TXREG ;work reg to TXREG (TXREG (0x19) not mirrored in other banks)
clrwdt ;Clear watchdog
btfss TXSTA,TRMT ;Wait until 'Q' is shifted (TXSTA is 0x18, not mirrored)
goto $-2
bcf PORTB,1 ;Set Recive DIR
Run Code Online (Sandbox Code Playgroud)
这同样有效:
BCF 0x3, 0x5 ;Switch to bank 0
BCF 0x3, 0x6
bsf PORTB,1 ;Set Transmit DIR
movlw 'Q' ;'Q' to work reg
movwf TXREG ;work reg …Run Code Online (Sandbox Code Playgroud) 我正在使用Python 2.7在os x 10.6上编写firefox 5.1和selenium webdrive v.2的测试套件.
除了创建单例类之外,一切都工作正常,这应该只保证一个firefox实例:
def singleton(cls):
instances = {}
def getinstance():
if cls not in instances:
instances[cls] = cls()
return instances[cls]
return getinstance
@singleton
class Fire(object):
def __init__(self):
self.driver = webdriver.Firefox()
def getdriver(self):
return self.driver
def close_(self):
self.driver.close()
def get(self, url):
self.driver.get(url)
return self.driver.page_source
f = Fire()
f.close_()
Run Code Online (Sandbox Code Playgroud)
此时如果我f=Fire() 再次打电话没有任何反应.不会创建新实例.我的问题是为什么我会看到这种行为?我怎么做的?
我的第二个问题,如果我输入:
isinstance(f, Fire)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
Run Code Online (Sandbox Code Playgroud)
这对我来说很奇怪......根据我的理解它应该回归 True
最后一个问题:
当我有单身课时,我应该能够做到:
f = …Run Code Online (Sandbox Code Playgroud) 似乎C#中的扩展方法不能覆盖原始对象.这是为什么?例:
using System;
namespace ExtensionTest
{
public class MyTest {
public string MyName { get; set; }
}
class Program
{
static void Main(string[] args)
{
var myTest = new MyTest() { MyName = "Arne" };
Console.WriteLine("My name is {0}", myTest.MyName);
// Will write "My name is Arne"
myTest.AlterMyTest();
Console.WriteLine("My name is {0}", myTest.MyName);
// Will write "My name is Bertil"
myTest.OverwriteMyTest();
Console.WriteLine("My name is {0}", myTest.MyName);
// Will write "My name is Bertil" (why?)
}
}
public static class …Run Code Online (Sandbox Code Playgroud)