小编glg*_*lgl的帖子

C 语言中带有 getaddrinfo() 的 Unix 套接字

有谁知道是否可以在 C (AF_UNIX) 中将 getaddrinfo 与 unix 套接字一起使用。我尝试了一些方法,但无法使其发挥作用。这基本上就是我正在尝试的:

struct addrinfo hints, *res;

memset(&hints, 0, sizeof(hints));
hints.ai_family   = AF_UNIX;
hints.ai_socktype = SOCK_STREAM;
if(getaddrinfo("What should I put here?", "What should I put here?", &hints, &res) != 0){
    //do sth about
}
Run Code Online (Sandbox Code Playgroud)

我的问题是如何填充节点和服务字段,以防可以将其与 unix 套接字一起使用。
提前致谢。

c sockets getaddrinfo

3
推荐指数
1
解决办法
4833
查看次数

创建表给出了无效的语法错误消息

使用以下代码时:

CREATE TABLE stats 
(
  username varchar(12), 
  starting text, 
  ending text, 
  UNIQUE (username)
)
Run Code Online (Sandbox Code Playgroud)

要么

CREATE TABLE stats 
(
  username varchar(12), 
  starting text, 
  ending blob, 
  UNIQUE (username)
)
Run Code Online (Sandbox Code Playgroud)

我收到一条错误消息:

您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在第1行的"起始文本,结束文本,UNIQUE(用户名)"附近使用正确的语法

难道我做错了什么?在添加ending text查询内部之前,它工作得很好.

mysql

3
推荐指数
1
解决办法
847
查看次数

使用file.write的Python语法无效

试图学习一些地理空间蟒蛇.或多或少遵循这里的课堂笔记.

我的守则

#!/usr/bin/python

# import modules
import ogr, sys, os

# set working dir
os.chdir('/home/jacques/misc/pythongis/data')

# create the text file we're writing to
file = open('data_export.txt', 'w')

# import the required driver for .shp
driver = ogr.GetDriverByName('ESRI Shapefile')

# open the datasource
data = driver.Open('road_surveys.shp', 1)
if data is None:
    print 'Error, could not locate file'
    sys.exit(1)

# grab the datalayer
layer = data.GetLayer()

# loop through the features
feature = layer.GetNextFeature()
while feature:

    # acquire attributes
    id …
Run Code Online (Sandbox Code Playgroud)

python geospatial

3
推荐指数
1
解决办法
5433
查看次数

如何找出对象是否具有属性?

 if groupName.group == "None":
Run Code Online (Sandbox Code Playgroud)

错误:

AttributeError: 'NoneType' object has no attribute 'group'
Run Code Online (Sandbox Code Playgroud)

如何检查对象是否具有属性?

python

3
推荐指数
2
解决办法
8225
查看次数

struct inet_sock中可打印的IPv6地址和端口

你知道以任何方式以可读格式打印ipv6地址及其来自inet_sock结构的端口吗?我的问题有两个部分.一个是具有此信息的结构成员,第二个是如何以可读格式打印它们.

谢谢!

linux kernel network-programming ipv6 linux-kernel

3
推荐指数
1
解决办法
1925
查看次数

python显式没有传递可选参数

想象一下以下场景:

class A:
    def __init__(self, arg1=3, arg2=5):
        pass

def createA(arg1=None, arg2=None):
    if arg1 is None:
        if arg2 is None:
            a = A()
        else:
            a = A(arg2=arg2)
    else:
        if arg2 is None:
            a = A(arg1=arg1)
        else:
            a = A(arg1=arg1, arg2=arg2)
    return a
Run Code Online (Sandbox Code Playgroud)

什么是实现此行为的最佳方式,请注意以下事项:

  • 我不能/不想改变课程 A
  • 我不想显式地将A构造函数的参数的默认值添加到createA函数中?

例如,是否有任何值表示未通过可选参数?就像是:

if arg1 is None:
    newArg1 = NotPassed
else:
    newArg1 = arg1

if arg2 is None:
    newArg2 = NotPassed
else:
    newArg2 = arg2
A(arg1=newArg1, arg2=newArg2)
Run Code Online (Sandbox Code Playgroud)

python optional-parameters

3
推荐指数
1
解决办法
2241
查看次数

期望'const char*'但参数在C中的类型为'char**'

我正在尝试编写一个函数来搜索查找指定键的数组.参数n指定数组的有效大小,必须根据strcmp强加的字典顺序进行排序.如果找到键,则函数返回数组中出现该键的索引.因此,它可以返回子字符串的索引.但是,它出现了两个我无法解决的错误.请帮忙.

jiebin@jiebin-ThinkPad-Edge-E530:~/Program_C/programming_abstractions_in_c/FindStringInSortedArray$ gcc FindStringInSortedArray.c -o FindStringInSortedArray
FindStringInSortedArray.c: In function ‘FindStringInSortedArray’:
FindStringInSortedArray.c:7:3: warning: passing argument 1 of ‘strlen’ from incompatible pointer type [enabled by default]
/usr/include/string.h:399:15: note: expected ‘const char *’ but argument is of type ‘char **’
jiebin@jiebin-ThinkPad-Edge-E530:~/Program_C/programming_abstractions_in_c/FindStringInSortedArray$
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

#include<stdio.h>
#include<string.h>

int FindStringInSortedArray(char *key,char *array[],int n)
{
  int mid,cmp;
  int low=strlen(array)-n;
  int high=n;
  if(low > high) return(-1);
  mid = (low+high)/2;
  cmp = strcmp(key,array[mid]);
  if(cmp==0) return(mid);
  if(cmp<0){
    return(FindStringInSortedArray(key,array,n/2));
   }else{
    return(FindStringInSortedArray(key,array+n/2,n));
   }
}

int main()
{
  char key[2]="ab";
  char *array[10]={"ab","bc","cd","de","ef","fg","gh","hi","ij","jk"};
  int test=FindStringInSortedArray(key,array,10); …
Run Code Online (Sandbox Code Playgroud)

c arrays pointers

3
推荐指数
1
解决办法
2万
查看次数

即使没有分配足够的内存,strcat()和strcpy()仍然有效

实现中缀到后缀,反之亦然算法

我发现,

char * str = (char*) malloc(1);
strcpy(str,str2);
Run Code Online (Sandbox Code Playgroud)

即使str2超过1个字符(20个字符或更多),这也可以工作.

我没有得到任何警告或运行时错误.

这怎么可能?

注意:

我也没有得到垃圾.

无论如何,我总是得到所需的结果str2.

c

3
推荐指数
1
解决办法
567
查看次数

__init __()在python子进程中得到了一个意外的关键字参数'timeout'

我正在尝试运行以下使用pythos'subprocess'模块的代码.

subprocess.call(cli_args, stdout=client_log, stderr=client_log, timeout=10)
Run Code Online (Sandbox Code Playgroud)

我正在使用超时争论,如果子进程卡在中间,通过杀死它,这里提到要跳过此行.但是当我运行它时,我得到了以下错误.

Traceback (most recent call last):
  File "test.py", line 152, in <module>
    ret = runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, transport, 9090, 0, 0)
  File "test.py", line 102, in runServiceTest
    ret = subprocess.call(cli_args, stdout=client_log, stderr=client_log, timeout=10)
  File "/usr/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
TypeError: __init__() got an unexpected keyword argument 'timeout'
Run Code Online (Sandbox Code Playgroud)

这是什么原因?我怎么解决这个问题?我的完整代码可以在这里找到.

python subprocess

3
推荐指数
1
解决办法
5899
查看次数

PYSide/PyQt Qtreewidget 字体颜色

我想知道如何将 QtreewidgetItem 字体颜色更改为预定义的 Qt 颜色以外的其他颜色。我想改用十六进制颜色代码,有什么想法吗?

QtGui.QTreeWidgetItem.setForeground(0,QtGui.QBrush(Qt.green)) 
Run Code Online (Sandbox Code Playgroud)

干杯!

python pyqt pyside

3
推荐指数
1
解决办法
4011
查看次数