我是Go的新手,我正在尝试编写一个逐行读取文件的简单脚本.我还想在某个文件系统上保存进度(即读取的最后一个行号),这样如果同一个文件再次作为脚本输入,它就会从它停止的行开始读取文件.以下是我的开始.
package main
// Package Imports
import (
"bufio"
"flag"
"fmt"
"log"
"os"
)
// Variable Declaration
var (
ConfigFile = flag.String("configfile", "../config.json", "Path to json configuration file.")
)
// The main function that reads the file and parses the log entries
func main() {
flag.Parse()
settings := NewConfig(*ConfigFile)
inputFile, err := os.Open(settings.Source)
if err != nil {
log.Fatal(err)
}
defer inputFile.Close()
scanner := bufio.NewScanner(inputFile)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
} …Run Code Online (Sandbox Code Playgroud) 我最近开始使用phabricator.我正在使用Arcanist CLI将差异提交给phabricator.直到昨天工作正常,今天每当我尝试创建新版本或更新现有版本时,它都会抛出错误.
这是我用来更新修订版的命令 D3
arc diff --update D3
Run Code Online (Sandbox Code Playgroud)
在我输入注释后,它会抛出以下异常
Linting...
No lint engine configured for this project.
Running unit tests...
No unit test engine is configured for this project.
Usage Exception: No changes found. (Did you specify the wrong commit range?)
Run Code Online (Sandbox Code Playgroud)
你们知道可能出现什么问题吗?
我正在使用Google App Engine搜索API(https://developers.google.com/appengine/docs/python/search/).我已将所有实体编入索引,搜索工作正常.但只有当我搜索完全匹配时,它才会返回0结果.例如:
from google.appengine.api import search
_INDEX_NAME = 'searchall'
query_string ="United Kingdom"
query = search.Query(query_string=query_string)
index = search.Index(name=_INDEX_NAME)
print index.search(query)
Run Code Online (Sandbox Code Playgroud)
如果我运行以下脚本,我会得到如下结果:
search.SearchResults(results='[search.ScoredDocument(doc_id='c475fd24-34ba-42bd-a3b5-d9a48d880012', fields='[search.TextField(name='name', value='United Kingdom')]', language='en', order_id='45395666'), search.ScoredDocument(doc_id='5fa757d1-05bf-4012-93ff-79dd4b77a878', fields='[search.TextField(name='name', value='United Kingdom')]', language='en', order_id='45395201')]', number_found='2')
Run Code Online (Sandbox Code Playgroud)
但是,如果我改变query_string对"United Kin"或"United"它返回0结果如下:
search.SearchResults(number_found='0')
Run Code Online (Sandbox Code Playgroud)
我想将此API用于普通搜索和AutoSuggest.实现这一目标的最佳方法是什么?
我想做的很简单.我想使用python的subprocess模块调用以下命令.
cat /path/to/file_A > file_B
Run Code Online (Sandbox Code Playgroud)
该命令只是工作并将内容复制file_A到file_B当前工作目录中.但是,当我尝试使用subprocess脚本中的模块调用此命令时,它会出错.以下是我正在做的事情:
import subprocess
subprocess.call(["cat", "/path/to/file_A", ">", "file_B"])
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
cat: /path/to/file_A: No such file or directory
cat: >: No such file or directory
cat: file_B: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么 ?如何在子进程模块call命令中使用大于运算符?
我有一个DialogFragment和它的布局我有一个EditText和一个ListView.Listview基本上显示了联系人列表(最初这个列表有0个项目).当edittext更新的值时,我使用text键入的联系人填充列表EditText.
在用户键入联系人的姓名或电子邮件地址时,EditText我使用了a addTextChangedListener来更新列表和所需的联系人.
我面临的一个奇怪的问题是,只有当我按下后退按钮以在键入后隐藏键盘时,列表(或者可能是布局)才会更新.只要软键盘显示,列表就不会更新(除非是第一次将项目添加到空列表中).
以下是一些更好理解的代码.
(在onCreateView中):
// Set list adapter for contacts list
contactsList = (ListView) shareView.findViewById(R.id.contactList);
emailContactAdapter = new EmailContactAdapter(getActivity(), emailContacts, shareFragment);
contactsList.setAdapter(emailContactAdapter);
// Implement Phone-book contact share
sendToInput = (EditText) shareView.findViewById(R.id.contact_name);
sendToInput.addTextChangedListener(onContactNameSearch);
Run Code Online (Sandbox Code Playgroud)
在onContactNameSearch(TextWatcher)中:
public TextWatcher onContactNameSearch = new TextWatcher() {
private generics commonMethods = new generics();
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
emailContacts.clear();
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我在我的一个应用程序中使用Ajax Autocomplete for Jquery(http://www.devbridge.com/projects/autocomplete/jquery/).搜索表单看起来像这样:
<form id="topsearch" method="POST" action="/searchAll"><input type="text" class="searchform" name="q" id="q" value="Country, City, Hotel or a Tourist Attraction" o nfocus="clearInput(this);" onblur="defaultInput(this);" />
<select id="top_search_select" name="entity_type">
<option value="country">Countries</option>
<option value="city">Cities</option>
<option value="place" selected="selected">Tourist Attractions</option>
<option value="hotel">Hotels</option>
</select>
<input type="submit" name="topsearch" class="submit" value="SEARCH" title="SEARCH"/>
</form>
Run Code Online (Sandbox Code Playgroud)
并且自动完成配置如下所示:
<script type="text/javascript">
//<![CDATA[
var a = $('#q').autocomplete({
serviceUrl:'/search',
delimiter: /(,|;)\s*/, // regex or character
maxHeight:400,
width:325,
zIndex: 9999,
params: {entity_type:$('#top_search_select').val()},
deferRequestBy: 0, //miliseconds
noCache: false, //default is false, set to true …Run Code Online (Sandbox Code Playgroud) 我是Android开发的新手,正在开发我的第一个Android应用程序.我在布局的xml中设置了View的背景颜色,如下所示.
android:background="@+color/bgColor"
Run Code Online (Sandbox Code Playgroud)
现在,我有一个全尺寸的透明背景图像,我想要在背景上,然后在该图像上的其他元素.
有没有办法可以在同一布局中使用背景颜色和背景图像.
提前致谢.
我最近在我的一个应用程序中集成了芹菜(django-celery更具体).我在应用程序中有一个模型如下.
class UserUploadedFile(models.Model)
original_file = models.FileField(upload_to='/uploads/')
txt = models.FileField(upload_to='/uploads/')
pdf = models.FileField(upload_to='/uploads/')
doc = models.FileField(upload_to='/uploads/')
def convert_to_others(self):
# Code to convert the original file to other formats
Run Code Online (Sandbox Code Playgroud)
现在,一旦用户上传文件,我想将原始文件转换为txt,pdf和doc格式.调用该convert_to_others方法是一个昂贵的过程,所以我打算使用芹菜异步.所以我写了一个简单的芹菜任务如下.
@celery.task(default_retry_delay=bdev.settings.TASK_RETRY_DELAY)
def convert_ufile(file, request):
"""
This task method would call a UserUploadedFile object's convert_to_others
method to do the file conversions.
The best way to call this task would be doing it asynchronously
using apply_async method.
"""
try:
file.convert_to_others()
except Exception, err:
# If the task fails …Run Code Online (Sandbox Code Playgroud) 检查两个给定列表中是否存在元素的最简单,最优雅的方法是什么?例如,我有两个列表如下?
>>>a, b = ['a', 'b', 'g', 'r'], ['e', 'g', 'l', 1, 'w']
Run Code Online (Sandbox Code Playgroud)
现在在上面给出的列表中,我想检查两个列表中是否存在任何元素.目前我正在做如下
def elm_exists(list_a, list_b):
for elm in list_a:
if elm in list_b:
return True
return False
Run Code Online (Sandbox Code Playgroud)
有更优雅的方式吗?
在我的一个django项目中,我使用了大量的自定义jquery脚本和大量的开源jquery插件.现在,如果我在我的基本模板中加载所有jquery脚本,我将在模板中加载大量未使用的javascript代码,这些代码不需要任何/一些已加载的jquery文件,这将影响页面加载时间特别的模板.
所以,我现在采取的方法是
{% block selective_js %}{% endblock selective_js %}上面的方法效果很好,但我看到的唯一问题是模板中有很多代码重复.比如说:
我有以下javascript文件
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.1.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.2.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.3.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.4.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.5.js"></script>
Run Code Online (Sandbox Code Playgroud)现在在多个模板中,我需要包含上面提到的所有javascript文件,并且还想要初始化所提到的脚本中的一些方法.所以目前,我必须在所有模板中执行此操作:
{% block selective_js %}
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.1.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.2.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.3.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.4.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.5.js"></script>
<!-- Initialize Methods -->
<script type="text/javascript">
$(document).ready(function() {
$('some_element').initializeScript();
});
</script>
{% …Run Code Online (Sandbox Code Playgroud)android ×2
django ×2
jquery ×2
python ×2
ajax ×1
autocomplete ×1
binaryfiles ×1
call ×1
celery ×1
command-line ×1
file ×1
go ×1
list ×1
load ×1
performance ×1
phabricator ×1
pickle ×1
readfile ×1
revision ×1
subprocess ×1
updates ×1