개발 일지

개발일기

kdhoooon 2019. 10. 29. 15:02

파이썬 연동을 할때 

takes exactly 1 argument (2 given)'

이라는 오류가 떴다.

 

알아보니 

These two calls are treated the same in all regards, including the error messages you get.

If you don't need to pass the instance to a method, you can use a staticmethod:

에러메세지와 함께 인자도 같이가서 그런것이다 인자는 한개인데 두개를 주고있어서..

@staticmethod  를적어 해결하였다.

 

@staticmethod
def enter(data):
return data

 

이렇게 적으니까 self 라는 인자를 꼭 안넣어도 됐다. 

 

  ScriptSource script = engine.CreateScriptSourceFromFile("C:\\Users\\User\\Desktop\\ImagineCup\\test.py");
  ScriptScope scope = engine.CreateScope();

  script.Execute(scope);

   dynamic w = scope.GetVariable("Enter")();
   image_frompy = w.enter(image_file) as string;

 

이건 내 컴퓨터 기준에서의 파일 위치를 넣어주고

 

spcript.Excute 를 통해 파일을 실행 시켜준다.

Enter 라는 class 를 선언해 놓았기 때문에

GetVariable("Enter")() 를 통해 클래스를 들어가고

w.enter() 를 통해 메소드를 실행시켜준다.

 

나머지 사진이 받아진 것을 확인하기 위해 

앞에서 쓴 winform 코드에서 picutreBox에 image_file 의 string 대신 

image_frompy 라는 새로운 string 변수를 선언하여 파이썬 코드에서 나온 결과값을 받아서

넣어줌으로써 값이 제대로 전달되어 오는지 확인을 하였다.

'개발 일지' 카테고리의 다른 글

개발일기  (0) 2019.11.19
개발일기  (0) 2019.11.19
개발일기  (0) 2019.10.26