我有一些Django应用程序仅用于CRUD的一些日常数据.
型号只有价格和日期.
我应该写一些代码,它会自动(每天)将新数据插入到我的模型中.
我打算使用BeautifulSoup进行网页解析.
所以我几乎没有问题:
我计划使用crontab(使用crontab -e手动编辑)将任务设置为每天运行一次.有更聪明的解决方案吗?
我应该使用Django ORM还是只在单独的脚本中编写SQL?
从长远来看,我正在寻找更好的建议.我会有更多这样的任务.
谢谢
我有以下代码
NSString * myStr = [[NSString alloc] initWithFormat:@""];
Run Code Online (Sandbox Code Playgroud)
但在Xcode中,我有一个带有"预期表达式"的红色感叹号.
我解决了以下问题:
[NSString stringWithFormat:@"Number is not from 1 to 6. randomNumber is %d", randomNumber]
Run Code Online (Sandbox Code Playgroud)
但我想知道问题是什么.
图片
http://imgur.com/iICMhYc&S7QwhFT#1
谢谢
我今天在iOS中发现了一些奇怪的东西,我解决了它,但我想问一下是否有更好的(更多iOS)解决方案.
我想要做的是:
循环遍历字典数组并为iOS中的每个字典添加新密钥
这是代码(这不是我的原始代码,它更复杂,但我完成了这个代码以说明容易点):
- (void)testLoopThruArrayOfDictionaryAndAddNewKeyToEachDictionary
{
NSMutableArray* a = [[NSMutableArray alloc] init];
[a addObjectsFromArray:@[ @{@"one": @11, @"two": @12, } ]];
[a addObjectsFromArray:@[ @{@"one": @21, @"two": @22, } ]];
NSLog(@"%@", a);
/*
// NOT WORKING
for (NSMutableDictionary* dict in a)
{
// -[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x8b5bca0
[dict setObject:@3 forKey:@"three"];
}
*/
// THIS IS WORKING
for (int i=0; i<[a count]; i++)
{
// make tmp copy
NSMutableDictionary *tmpA = [a[i] mutableCopy];
[tmpA setObject:@3 forKey:@"three"];
// put …Run Code Online (Sandbox Code Playgroud) objective-c nsdictionary nsmutablearray nsarray nsmutabledictionary
我有工作代码,但不确定这是实现它的正确方法。
CLi 程序将接受 4 个参数,可以存在零个、全部或之间的任意组合。
这是工作代码:
#[derive(Parser, Default, Debug)]
struct Arguments {
#[clap(short, long, default_value_t = false)]
/// if areas.csv to download
areas: bool,
#[clap(short, long, default_value_t = false)]
/// if markers.csv to download
markers: bool,
#[clap(short, long, default_value_t = false)]
/// if tracks.csv to download
tracks: bool,
#[clap(short, long)]
/// path to file of GPS tracks to download
gpx_list_file: Option<String>,
}
Run Code Online (Sandbox Code Playgroud)
我不喜欢的是在 -h 部分中没有办法知道它们是可选的。
Options:
-a, --areas if areas.csv to download
-m, --markers if markers.csv to download
-t, --tracks …Run Code Online (Sandbox Code Playgroud) 我有使用sqlite作为数据库的Django应用程序.我不会使视图能够下载该sqlite文件.
这是我到目前为止所得到的:
def backup(request):
"""Return Sqlite3 db file, if Sqlite3 db is used."""
import settings
db_engine = settings.DATABASES['default']['ENGINE']
#db_engine = 'JUST_FOR_TESTING'
if db_engine == 'django.db.backends.sqlite3':
db_path = settings.DATABASES['default']['NAME']
response = HttpResponse(mimetype='application/x-sqlite3')
response['Content-Disposition'] = 'attachment; filename=%s' % db_path
response.write(db_path)
return HttpResponse(response)
else:
return HttpResponse("settings.DATABASES['default']['ENGINE'] is %s,<br />\
only for 'django.db.backends.sqlite3' online backup is posible." % (db_engine))
Run Code Online (Sandbox Code Playgroud)
我缺少的是如何将该文件添加为附件.
也有办法以某种方式只下载特定的表?
我不确定这是否可行,但无论如何我都会问.
这是我的ViewController.h
@interface TBL_GameViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *roundText;
@property (strong, nonatomic) IBOutlet UILabel *roundNumber;
@property (strong, nonatomic) IBOutlet UILabel *playerText;
@property (strong, nonatomic) IBOutlet UILabel *playerScore;
@property (strong, nonatomic) IBOutlet UILabel *computerText;
@property (strong, nonatomic) IBOutlet UILabel *computerScore;
@end
Run Code Online (Sandbox Code Playgroud)
这是.m文件中的一种方法
- (void) lablesHiden:(BOOL)on
{
self.roundText.hidden = on;
self.roundNumber.hidden = on;
self.playerText.hidden = on;
self.playerScore.hidden = on;
self.computerText.hidden = on;
self.computerScore.hidden = on;
}
Run Code Online (Sandbox Code Playgroud)
这一切都是工作文件.
问题
是以编程方式访问视图控制器中所有可用标签的某种方法吗?
我之所以这样问的原因是:
我将有大约10种方法需要访问这些标签,以更改各种属性(颜色,文本,......).
如果明天我添加更多标签,我还需要为所有这些方法添加新标签,我想避免这种情况?
更新
我最后使用这种方法
- (NSArray*) getAllLabels
{
NSArray …Run Code Online (Sandbox Code Playgroud) 在此链接(https://docs.python.org/2/tutorial/errors.html#defining-clean-up-actions)下面说:
在离开try语句之前总是执行finally子句,无论是否发生了异常.
代码1:
try:
print "Performing an action which may throw an exception."
except Exception, error:
print "An exception was thrown!"
print str(error)
else:
print "Everything looks great!"
finally:
print "Finally is called directly after executing the try statement whether an exception is thrown or not."
Run Code Online (Sandbox Code Playgroud)
输出1:
Performing an action which may throw an exception.
Everything looks great!
Finally is called directly after executing the try statement whether an exception is thrown or not.
Run Code Online (Sandbox Code Playgroud)
代码2:
try:
print "Performing …Run Code Online (Sandbox Code Playgroud) objective-c ×3
python ×3
django ×2
ios ×2
clap ×1
exception ×1
nsarray ×1
nsdictionary ×1
nsstring ×1
rust ×1
uilabel ×1
web-crawler ×1
xcode ×1