关于使用函数的问题struct.我从R.Stevens的书中拿走了片段,我看了几次相似的片段.我建议获得一些C和Linux经验,但在这种情况下我真的不知道如何以正确的方式使用struct.
struct stat buf; // The error line
for (i=1; i < argc; i++){
if (lstat(argv[i], &buf) < 0) { // Usage of
err_ret("lstat error");
continue;
}
if (S_ISERG(buf.st_mode))
ptr = "regular";
Run Code Online (Sandbox Code Playgroud)
当我编译我的代码时,我遇到了一个错误:
type.c: In function ‘main’:
type.c:9:15: error: storage size of ‘buf’ isn’t known
Run Code Online (Sandbox Code Playgroud)
结构声明有什么问题?我应该明确声明结构大小吗?如果是,我怎么知道呢?主要问题 - 它是如何运作的struct method name?
我的Django版本是1.2.5,它在Python 2.6.5中运行.我从Ubuntu软件中心安装了debug_toolbar,它没有模块命名消息错误.使用debug_toolbar版本的Django - 1.1.1,没有debug_toolbar - 1.2.5.当我删除它时,Django运行良好.debug_toolbar有什么问题?我该如何解决?
安装前:
>>> import django
>>> django.VERSION
(1, 2, 5, 'final', 0)
i159@i159-desktop:~/djproj/pastebin$ python2.6 manage.py runserver
Validating models...
0 errors found
...
Run Code Online (Sandbox Code Playgroud)
安装后:
>>> import django
>>> django.VERSION
(1, 1, 1, 'final', 0)
i159@i159-desktop:~/djproj/pastebin$ python2.6 manage.py runserver
Error: No module named messages
Run Code Online (Sandbox Code Playgroud) 我有一个全球性问题和一个关于信号背景下特定问题的问题.为了解决这些问题,信号调度员最有用,是否过度?
我有一个使用外键保存多个模型的问题.我认为这个信号可以解决它.但我不知道如何,因为我不明白信号的范围.
模型
class CV(models.Model):
title = models.CharField(max_length=255)
# And other fields...
class HigherEducation(models.Model):
cv = models.ForeignKey(CV, blank=True, null=True)
institution = models.CharField(max_length=255)
# And other fields...
class ProfessionalExperience(models.Model):
cv = models.ForeignKey(CV, blank=True, null=True)
company_name = models.CharField(max_length=255)
# And other fields...
Run Code Online (Sandbox Code Playgroud)
所有表单都是从上面的模型继承的模型.最后两个用于modelformsets.所有这些表单都以模板中的一个html格式显示.
形式
class CVForm(forms.ModelForm):
class Meta:
# All the stuff
class EducationForm(forms.ModelForm):
class Meta:
# All the stuff
class ExperienceForm(forms.ModelForm):
class Meta:
# All the stuff
Education = modelformset_factory(HigherEducation,
form=EducationForm,
max_num=2)
Experience = modelformset_factory(ProfessionalExperience,
form=ExperienceForm,
max_num=1)
Run Code Online (Sandbox Code Playgroud)
在视图中,我需要使用当前模型的指定ID 保存EducationForm …
例如,我需要类调用返回字符串.
class Foo(object):
def __init__(self):
self.bar = 'bar'
def __call__(self):
return self.bar
Run Code Online (Sandbox Code Playgroud)
Foo调用返回Foo object.
Foo()
<__main__.Foo object at 0x8ff6a8c>
Run Code Online (Sandbox Code Playgroud)
我应该怎么做类返回字符串或其他?怎么用__call__?
我理解简单的有向图解释如下:
graph = {1: [2], 2: [3], 3: [4, 5, 1], 4: [], 5: [4]}
# 1
# / .
# / \
# . \
# 4--.3 ------.2
# \ .
# \ |
# .5
Run Code Online (Sandbox Code Playgroud)
但不知道如何解释dicts的dict,例如:
{1: {2: 3, 3: 8, 5: -4}, 2: {4: 1, 5: 7}, 3: {2: 4}, 4: {1: 2, 3: -5}, 5: {4: 6}}
Run Code Online (Sandbox Code Playgroud)
是加权图吗?我应该怎么理解这种图表写的?
如果您决定对此问题进行投票,请在评论中留下相应文章的链接.
请帮我理解BBS算法。我做了这个实现:
class EmptySequenseError(Exception):
pass
class BlumBlumShub(object):
def __init__(self, length):
self.length = length
self.primes = e(1000) # Primes obtained by my own Sieve of Eratosthenes implementation.
def get_primes(self):
out_primes = []
while len(out_primes) < 2:
curr_prime = self.primes.pop()
if curr_prime % 4 == 3:
out_primes.append(curr_prime)
return out_primes
def set_random_sequence(self):
p, q = self.get_primes()
m = p * q
self.random_sequence = [((x+1)**2)%m for x in range(self.length)]
def get_random_sequence(self):
if self.random_sequence:
return self.random_sequence
raise EmptySequenseError("Set random sequence before get it!")
Run Code Online (Sandbox Code Playgroud)
我有几个问题。一开始不想用random库,太天真了。我的顺序是递增的,不是绝对随机的。 …
我使用Angular从Rest调用发送base64字符串到Golang服务器.现在的问题是使用此字符串创建图像.
我的代码:
func (server *Server) uploadImage(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
defer r.Body.Close()
var d model.ImageFile
err := decoder.Decode(&d)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Println(d.Source)
fmt.Println(d.Destination)
fmt.Println(d.Country)
dir, errr := filepath.Abs(filepath.Dir(os.Args[0]))
if errr != nil {
fmt.Println(errr)
}
substring := dir[0:(len(dir) - 10)]
unbased, err := base64.StdEncoding.DecodeString(d.ImageData)
if err != nil {
fmt.Println("Cannot decode b64")
}
r = bytes.NewReader(unbased)
im, err := png.Decode(r)
if err != nil {
fmt.Println("Bad png")
}
f, err …Run Code Online (Sandbox Code Playgroud) 我需要有关在vim中使用正则表达式进行搜索的最佳方法的建议,并提取所发现的任何匹配项.
我有一个csv文件,看起来像这样:
两个领域:
ID
描述
0g98932,"长描述有时包含1234567,或0000012345甚至BR00012345但始终包含文本的数字"
我需要搜索每一行的描述字段.如果第二个字段中存在匹配\ d {10}的数字,我想将其拉出来.
做点什么:% s/(\d{10})/^$1/g给我一个
找不到模式(\ d {10})错误.
我从来没有学过如何从vim中的正则表达式搜索中获取和引用匹配 - 所以这是问题的一部分.
另一部分:
我真的很想.
我听说可以if用lambda 替换一个语句.
这在Python中可行吗?如果是这样,怎么样?
我有postgreSQL 8.4 + PostGIS 1.5.
我想生成GeoJson.我做:
SELECT row_to_json(fc)
FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features
FROM (SELECT 'Feature' As type
, ST_AsGeoJSON(lg.the_geom)::json As geometry
, row_to_json(lp) As properties
FROM parcels_temp As lg
INNER JOIN (SELECT num, cadastr FROM parcels_temp) As lp
ON lg.num = lp.num ) As f ) As fc;
Run Code Online (Sandbox Code Playgroud)
但得到一个错误:
ERROR: type "json" does not exist
LINE 4: , ST_AsGeoJSON(lg.the_geom)::json As geometry
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
python ×4
django ×2
algorithm ×1
base64 ×1
c ×1
cryptography ×1
dictionary ×1
function ×1
go ×1
graph ×1
hashmap ×1
if-statement ×1
image ×1
lambda ×1
postgis ×1
postgresql ×1
regex ×1
struct ×1
vim ×1