在这篇文章中,我们将带领您了解Python:ObjectSerializationwithpickle的全貌,同时,我们还将为您介绍有关Angular10:运行ngxi18n时无法解析SomeComp
在这篇文章中,我们将带领您了解Python: Object Serialization with pickle的全貌,同时,我们还将为您介绍有关Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数、angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、Appium - multiprocessing.pool.MaybeEncodingError-【 “Can’t pickle local object ‘PoolManager.__init...、ASP.NET list的知识,以帮助您更好地理解这个主题。
本文目录一览:- Python: Object Serialization with pickle
- Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数
- angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
- Appium - multiprocessing.pool.MaybeEncodingError-【 “Can’t pickle local object ‘PoolManager.__init...
- ASP.NET list
Python: Object Serialization with pickle
Serialization:
#!/usr/bin/env python
import cPickle as pickle
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.dirname(sys.argv[0])))
class Package(object):
def __init__(self, pn, pv):
self.pn = pn
self.pv = pv
def __str__(self):
return str(self.pn)+'' ''+str(self.pv)
def serialize(cachefile, *listPackages):
''''''
serialize a list of packages to the specified cache file
''''''
pickler = pickle.Pickler(cachefile)
for package in listPackages:
pickler.dump(package)
def main(argv=None):
if len(argv) != 1:
cachefile = ''tmp.dat''
else:
cachefile = argv[0]
p1 = Package(''package1'', 1.0)
p2 = Package(''package1'', 2.0)
p3 = Package(''package1'', 3.0)
p4 = Package(''package1'', 4.0)
p5 = Package(''package1'', 5.0)
with open(cachefile, ''wb'') as cachefile:
serialize(cachefile, p1, p2, p3, p4, p5)
if __name__ == ''__main__'':
main(sys.argv[1:])
De-serialization
#!/usr/bin/env python
import cPickle as pickle
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.dirname(sys.argv[0])))
from serialize import Package
def main(argv=None):
''''''
read the cache file and print the contents
''''''
if len(argv) != 1:
cachefile = ''tmp.dat''
else:
cachefile = argv[0]
with open(cachefile, ''rb'') as cachefile:
pickled = pickle.Unpickler(cachefile)
while cachefile:
try:
package = pickled.load()
except:
break
if isinstance(package, Package):
print package
if __name__ == ''__main__'':
main(sys.argv[1:])
Result
chenqi@chenqi-OptiPlex-760:~/mypro/python$ ./serialize.py cache.dat
chenqi@chenqi-OptiPlex-760:~/mypro/python$ ./de-serialize.py cache.dat
package1 1.0
package1 2.0
package1 3.0
package1 4.0
package1 5.0
Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数
如何解决Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数
应用运行/构建良好,但是当我尝试运行 List<SubItem> tempSplitFilesList = new ArrayList<>(); List<SubItem> splitFilesList = new ArrayList<>(); for (SubItem item1 : tempSplitFilesList) { for (SubItem item2 : tempSplitFilesList) { if (item1.getStop().equals(item2.getStart())) { splitFilesList.add(item2); } } }
时,我得到 ng xi18n --output-path src/translate
从错误中我可以假设它是导致问题的构造函数中的第一个参数,但是,我的构造函数看起来像这样:
ERROR in Can''t resolve all parameters for SomeComponent in /path/some.component.ts: (?,[object Object],[object Object]).
被扩展的类的构造函数如下所示:
constructor(
$window: Window,service1: Service1,service2: Service2
) {
super($window,service1,Service2);
}
似乎这些错误通常来自注射和/或放置在枪管中的问题?如果是这样,window 是如何在这里出错的,或者它可能是完全不相关的东西?
解决方法
问题似乎与错误注入 Window 一样简单。编写一个自定义服务来处理它解决了这个问题。您可以在这里找到正确的注入方式:How to inject window into a service?
angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
Can’t resolve all parameters for AuthenticationService: ([object Object],?,[object Object])
我已经检查了几乎每个主题,并尝试了多种方法来解决它,但仍然无法在第二天击败它.
我试图像这样在appService中注入第一个authService但是得到了同样的错误
@Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService
我检查了所有DI和服务内部的导入顺序,在我看来一切都是正确的
如果有人可以帮我处理它,我很感激.
Angular 4.0.0
AuthService
import { Injectable } from '@angular/core'; import {Http,Headers,Response} from '@angular/http'; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; import {AppServices} from "../../app.services"; import {Router} from "@angular/router"; @Injectable() export class AuthenticationService { public token: any; constructor( private http: Http,private appService: AppServices,private router: Router ) { this.token = localStorage.getItem('token'); } login(username: string,password: string): Observable<boolean> { let headers = new Headers(); let body = null; headers.append("Authorization",("Basic " + btoa(username + ':' + password))); return this.http.post(this.appService.api + '/login',body,{headers: headers}) .map((response: Response) => { let token = response.json() && response.json().token; if (token) { this.token = token; localStorage.setItem('Conform_token',token); return true; } else { return false; } }); } logout(): void { this.token = null; localStorage.removeItem('Conform_token'); this.router.navigate(['/login']); } }
应用服务
import {Injectable} from '@angular/core'; import {Headers,Http,RequestOptions} from '@angular/http'; import {Router} from "@angular/router"; import {AuthenticationService} from "./auth/auth.service"; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; @Injectable() export class AppServices { api = '//endpoint/'; public options: any; constructor( private http: Http,private router: Router,public authService: AuthenticationService // doesn't work // @Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService // doesn't work either ) { let head = new Headers({ 'Authorization': 'Bearer ' + this.authService.token,"Content-Type": "application/json; charset=utf8" }); this.options = new RequestOptions({headers: head}); } // ==================== // data services // ==================== getData(): Promise<any> { return this.http .get(this.api + "/data",this.options) .toPromise() .then(response => response.json() as Array<Object>) .catch((err)=>{this.handleError(err);}) }
应用模块
import { browserModule } from '@angular/platform-browser'; import { browserAnimationsModule } from '@angular/platform-browser/animations'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import {BaseRequestOptions,HttpModule} from '@angular/http'; import { MaterialModule} from '@angular/material'; import {FlexLayoutModule} from "@angular/flex-layout"; import 'hammerjs'; import { routing,appRoutingProviders } from './app.routing'; import { AppServices } from './app.services'; import {AuthGuard} from "./auth/auth.guard"; import {AuthenticationService} from "./auth/auth.service"; import {AppComponent} from './app.component'; import {AuthComponent} from './auth/auth.component'; import {NotFoundComponent} from './404/not-found.component'; import { HomeComponent } from './home/home.component'; @NgModule({ declarations: [ AppComponent,AuthComponent,NotFoundComponent,HomeComponent ],imports: [ browserModule,browserAnimationsModule,FormsModule,HttpModule,routing,MaterialModule,FlexLayoutModule ],providers: [AppServices,AuthGuard,AuthenticationService],bootstrap: [AppComponent] }) export class AppModule { }
解决方法
你可以使用
export class AuthenticationService { public token: any; appService: AppServices; constructor( private http: Http,// private appService: AppServices,injector:Injector; private router: Router ) { setTimeout(() => this.appService = injector.get(AppServices)); this.token = localStorage.getItem('token'); }
另见DI with cyclic dependency with custom HTTP and ConfigService
要避免使用setTimeout,您还可以从AppService的构造函数中设置AuthenticationService.appService(或者相反)
Appium - multiprocessing.pool.MaybeEncodingError-【 “Can’t pickle local object ‘PoolManager.__init...
公司同事学习自动化新装环境后,run多进程测试用例时出错:
multiprocessing.pool.MaybeEncodingError: Error sending result: ’<appium.webdriver.webdriver.WebDriver (session=“261019ae-3776-4a78-aa2c-b24bb64ec62e”)>’. Reason: ’AttributeError(“Can’t pickle local object ‘PoolManager.__init__.<locals>.<lambda>‘“)’
同一份代码,我本地并没有这种情况
在网上搜索到三种方法:
1.用线程替换进程
2.可以使用copy_reg来规避上面的异常.
3.dill 或pathos.multiprocesssing :use ''import pathos.multiprocesssing'', instead of ''import multiprocessing''. pathos.multiprocessing is a fork of multiprocessing that uses dill. dill can serialize almost anything in python, so you are able to send a lot more around in parallel.
最开始采用了方法3:use ''import pathos.multiprocesssing'', instead of ''import multiprocessing'' ,然后程序并不在抛出该错误,但是启动case后,appium启动driver后便不在干活(使用两个进程分别在不同端口启动driver),appium log没有错误,pycharm也一直转转转卡在那不去执行find element, 所以还是还原到使用import multiprocessing
最终解决方案如下:
1. mac裡面的python都刪乾淨
2. 用pyenv裝python 3.5.2
3. 執行multi process case script
4. 把該裝的selenium, Pillow, requests裝一裝
5. 最後一步降级appium-python-client : pip install appium-python-client==0.25 (这个是重点,可以忽略其他步骤直接降级版本,这里是因为需要才重装, 当然笔者local的0.31版本也可以的,就是最新版(0.43)有问题)
6. 成功!
ASP.NET list
public partial class 测试 : System.Web.UI.Page
{
static List<Item> allAnswer= new List<Item>();
protected void Page_Load(object sender, EventArgs e)
{
//首次加载
if (IsPostBack == false)
{
//不能使用将allAnswer中的元素全部删除,这样也会将session中的值清空
//allAnswer.clean();
//使用重新定义新的空的对象来实现对allAnswer的清空
allAnswer = new List<Item>();
List<Item> reallAnswer = null;
try
{
//其中Session["ReAllAnswer"]来自于另一页面
reallAnswer = (List<Item>)Session["ReAllAnswer"];
//PrintAllAnwser(reallAnswer);
}
catch { }
}
}
如果使用allAnswer.clean()函数,则接收的数据Session["ReAllAnswer"]将会设置为空;
而使用new List<Item>(),则不会。
今天关于Python: Object Serialization with pickle的讲解已经结束,谢谢您的阅读,如果想了解更多关于Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数、angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、Appium - multiprocessing.pool.MaybeEncodingError-【 “Can’t pickle local object ‘PoolManager.__init...、ASP.NET list的相关知识,请在本站搜索。
本文标签: